Forum Discussion

richie's avatar
richie
Community Hero
6 years ago
Solved

Execution Stats TearDown Script By Lucian

Hey!

 

TI am using a script Lucian developed to record my execution stats.   Its a teardown script I've stuck at project level at moment and is as follows:

 

It's fantastic - does almost everything I want.  Currently it iteratively runs through each of the testsuites and returns the pass/fail numbers for the tests in each testsuite in the project.  This is great - but on top of the current stats returned I need it to return a total executed, total PASS and total FAIL for the project after all the other stats have been returned, rather than at testsuite level which is what it's doing at the moment. 

 

I think I could probably do that if the script wasn't iterative - if the script parked the values into variables that I could add up at the end - I think I could do that - but I just dont know where to start to alter the existing to give me those extra project level stats - or maybe it is easy and I'm just being dumb!?!? ;)

 

// Define variables for holding test suites, test cases and test steps
def testSuites
def testCases
def passedTestCases = 0
def failedTestCases = 0

// Get the list of test suites
testSuites = runner.getResults() 

// Iterate through each test suite
testSuites.each() {
	log.info "----------------------------------------"
	log.info "The " + "'" + it.getTestSuite().getName() +"'" + " test suite has " + it.getStatus() + "ED."
	log.info "Test case execution results as follows..."

	// Get all the test cases and iterate through them
	testCases = it.getResults()
	testCases.each() {
		log.info "Test case " + "'" + it.getTestCase().getName() + "' " + it.getStatus() + "ED."
		if ( it.getStatus().toString().equals("PASS") ) {
			passedTestCases++
		} else {
			failedTestCases++
		}
	}

	log.info " Number of PASSES = " + passedTestCases.toString() + " Number of FAILS = " + failedTestCases.toString() + "."
	passedTestCases = 0
	failedTestCases = 0
}

 

 

If anyone could give me a steer - I'd appreciate it - I just don't know where to start to alter the script accordingly.

 

As always - props to the originator of the work (Lucian) - I can't take credit! :)

 

nice one

 

richie

  • Opps... Sorry...

     

    The following code is very "rough and ready" and I don't have time to fully test and refine, but try the following:

     

    // Define variables for holding test suites, test cases and test steps
    def testSuites
    def testCases
    def totalPassedTestCases = 0
    def totalFailedTestCases = 0
    
    def testSuitePassTotals = []
    def testSuiteFailTotals = []
    
    // Get the list of test suites
    testSuites = runner.getResults() 
    
    // Iterate through each test suite
    testSuites.each() {
    	log.info "----------------------------------------"
    	log.info "The " + "'" + it.getTestSuite().getName() +"'" + " test suite has " + it.getStatus() + "ED."
    	log.info "Test case execution results as follows..."
    
    	// Get all the test cases and iterate through them
    
    	def testSuitePassedTestCases = 0
    	def testSuiteFailedTestCases = 0
    			
    	testCases = it.getResults()
    	testCases.each() {
    		log.info "Test case " + "'" + it.getTestCase().getName() + "' " + it.getStatus() + "ED."
    		if ( it.getStatus().toString().equals("PASS") ) {
    			totalPassedTestCases++
    			testSuitePassedTestCases++
    		} else {
    			totalFailedTestCases++
    			testSuiteFailedTestCases++
    		}
    	}
    
    	testSuitePassTotals.add([name:it.getTestSuite().getName(), count:testSuitePassedTestCases])
    	testSuiteFailTotals.add([name:it.getTestSuite().getName(), count:testSuiteFailedTestCases])
    	
    }
    
    log.info "----------------------------------------" testSuitePassTotals.each(){ log.info('Test Suite "' + it.name + '" number of passed test cases = ' + it.count) }
    log.info "----------------------------------------" testSuiteFailTotals.each(){ log.info('Test Suite "' + it.name + '" number of failed test cases = ' + it.count) }
    log.info "----------------------------------------" log.info " Number of PASSES = " + totalPassedTestCases.toString() + " Number of FAILS = " + totalFailedTestCases.toString() + "."

     

    Note sure if it's exactly what you want, but hopefully it might point you in the right direction.

4 Replies

  • Radford's avatar
    Radford
    Super Contributor

    Does the following give you what you want? I've just removed the resetting of the pass/fail counters, and then moved the logging of the totals to the very end.

     

    // Define variables for holding test suites, test cases and test steps
    def testSuites
    def testCases
    def passedTestCases = 0
    def failedTestCases = 0
    
    // Get the list of test suites
    testSuites = runner.getResults() 
    
    // Iterate through each test suite
    testSuites.each() {
    	log.info "----------------------------------------"
    	log.info "The " + "'" + it.getTestSuite().getName() +"'" + " test suite has " + it.getStatus() + "ED."
    	log.info "Test case execution results as follows..."
    
    	// Get all the test cases and iterate through them
    	testCases = it.getResults()
    	testCases.each() {
    		log.info "Test case " + "'" + it.getTestCase().getName() + "' " + it.getStatus() + "ED."
    		if ( it.getStatus().toString().equals("PASS") ) {
    			passedTestCases++
    		} else {
    			failedTestCases++
    		}
    	}
    }
    
    log.info " Number of PASSES = " + passedTestCases.toString() + " Number of FAILS = " + failedTestCases.toString() + "."
    
    • richie's avatar
      richie
      Community Hero

      Radford

       

      hahaha! - almost - it gives me the total execution stats across the whole project now, but I lose the 'per test suite' stats when I apply the change you suggest.

       

      I need to keep the 'per suite' SUB TOTAL (like the old version of script) AND the 'per project' TOTAL (like your version of the script) - I need both - not one nor just the other.

       

      I'm stuffed -  either reset the stat counters each iteration (to keep the per suite stats) or remove them and have logging at the end to have a cumulative (per project count).

       

      Thanks man - appreciate the help - I'm gonna keep digging! :)

       

      richie

      • Radford's avatar
        Radford
        Super Contributor

        Opps... Sorry...

         

        The following code is very "rough and ready" and I don't have time to fully test and refine, but try the following:

         

        // Define variables for holding test suites, test cases and test steps
        def testSuites
        def testCases
        def totalPassedTestCases = 0
        def totalFailedTestCases = 0
        
        def testSuitePassTotals = []
        def testSuiteFailTotals = []
        
        // Get the list of test suites
        testSuites = runner.getResults() 
        
        // Iterate through each test suite
        testSuites.each() {
        	log.info "----------------------------------------"
        	log.info "The " + "'" + it.getTestSuite().getName() +"'" + " test suite has " + it.getStatus() + "ED."
        	log.info "Test case execution results as follows..."
        
        	// Get all the test cases and iterate through them
        
        	def testSuitePassedTestCases = 0
        	def testSuiteFailedTestCases = 0
        			
        	testCases = it.getResults()
        	testCases.each() {
        		log.info "Test case " + "'" + it.getTestCase().getName() + "' " + it.getStatus() + "ED."
        		if ( it.getStatus().toString().equals("PASS") ) {
        			totalPassedTestCases++
        			testSuitePassedTestCases++
        		} else {
        			totalFailedTestCases++
        			testSuiteFailedTestCases++
        		}
        	}
        
        	testSuitePassTotals.add([name:it.getTestSuite().getName(), count:testSuitePassedTestCases])
        	testSuiteFailTotals.add([name:it.getTestSuite().getName(), count:testSuiteFailedTestCases])
        	
        }
        
        log.info "----------------------------------------" testSuitePassTotals.each(){ log.info('Test Suite "' + it.name + '" number of passed test cases = ' + it.count) }
        log.info "----------------------------------------" testSuiteFailTotals.each(){ log.info('Test Suite "' + it.name + '" number of failed test cases = ' + it.count) }
        log.info "----------------------------------------" log.info " Number of PASSES = " + totalPassedTestCases.toString() + " Number of FAILS = " + totalFailedTestCases.toString() + "."

         

        Note sure if it's exactly what you want, but hopefully it might point you in the right direction.