The beforeTest(Closure)
method is just a shortcut you can use in Groovy. Ultimately, it maps the closure to receive broadcasts the same as the TestListener
interface. You can clean up how you handle this vs. using the anonymous class, but essentially:
test.addTestListener(new TestListener() {
void beforeSuite(TestDescriptor suite) {}
void afterSuite(TestDescriptor suite, TestResult result) {}
void beforeTest(TestDescriptor testDescriptor) {
println("Starting " + testDescriptor.toString());
}
void afterTest(TestDescriptor testDescriptor, TestResult result) {}
});