A quick way to get the duration of a test using Groovy

From a previous test I worked on, I wanted to point out how to record the execution time of a test. It uses the TimeCategory and TimeDuration libraries. Since my API test doesn't run within a Test Suite, it doesn't record the execution time, but it's still possible to get that information using code similar to the following.

import groovy.time.TimeCategory 
import groovy.time.TimeDuration

def timeStart = new Date()

//Test Code goes between the Start and Stop definitions

def timeStop = new Date()
TimeDuration duration = TimeCategory.minus(timeStop, timeStart)

log.logWarning("Execution Time: " + duration)
Handcrafted with care just for you.

Author Signature for Posts