http://junit.sourceforge.net/javadoc/org/junit/runner/notification/RunListener.html
org.junit.runner.notification
Class RunListener
java.lang.Object org.junit.runner.notification.RunListener
public class RunListenerextends java.lang.Object
If you need to respond to the events during a test run, extend RunListener
and override the appropriate methods. If a listener throws an exception while processing a test event, it will be removed for the remainder of the test run.
For example, suppose you have a Cowbell
class that you want to make a noise whenever a test fails. You could write:
public class RingingListener extends RunListener {
public void testFailure(Failure failure) {
Cowbell.ring();
}
}
public void testFailure(Failure failure) {
Cowbell.ring();
}
}
To invoke your listener, you need to run your tests through JUnitCore
.
public void main(String... args) {
JUnitCore core= new JUnitCore();
core.addListener(new RingingListener());
core.run(MyTestClass.class);
}
JUnitCore core= new JUnitCore();
core.addListener(new RingingListener());
core.run(MyTestClass.class);
}