Knowledge Base Article

Test run groovy statistics

 

Solution

Here is a script which logs in the status of the test suites / test cases.

// 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 test suite " + "'" + it.getTestSuite().getName() +"'" + " has the status " + it.getStatus() + "."
	log.info "The following are the contained test cases..."

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

	log.info "The number of passed test cases is " + passedTestCases.toString() + " while the number of failed test cases is " + failedTestCases.toString() + "."
	passedTestCases = 0
	failedTestCases = 0
}
Published 4 years ago
Version 1.0
No CommentsBe the first to comment