Listener is always Hudson-wide, so once registered it gets notifications for every build that happens in this Hudson.
This is an abstract class so that methods added in the future won't break existing listeners. @author Kohsuke Kawaguchi @since 1.145
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(); } }
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); }
If a listener throws an exception for a test event, the other listeners will have their {@link RunListener#testFailure(Failure)} called with a {@code Description}of {@link Description#TEST_MECHANISM} to indicate the failure.
By default, JUnit will synchronize calls to your listener. If your listener is thread-safe and you want to allow JUnit to call your listener from multiple threads when tests are run in parallel, you can annotate your test class with {@link RunListener.ThreadSafe}.
Listener methods will be called from the same thread as is running the test, unless otherwise indicated by the method Javadoc @see org.junit.runner.JUnitCore @since 4.0
|
|
|
|