Forum Discussion

Lucian's avatar
Lucian
Community Hero
6 years ago

Sharing is caring - groovy script to log the test execution duration for every test suite/test case

The following is a TearDown script to log test execution duration for every test suite and test case.

 

// Define variables for holding test suites, test cases and test steps
def testSuites
def testCases

// 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() +"'" + " took " + it.getTimeTaken() + "ms to finish."
	log.info "The following are the contained test cases along with their durations..."

	// Get all the test cases and iterate through them
	testCases = it.getResults()
	testCases.each() {
		log.info "...the test case " + "'" + it.getTestCase().getName() +"'" + " - " + it.getTimeTaken() + "ms."
	}
}

1 Reply

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Thanks for sharing the sample, Lucian!

     

    Community, has anyone already tried the sample? Any questions/suggestions/comments?