Package org.junit.runner.notification
Class RunListener
- java.lang.Object
-
- org.junit.runner.notification.RunListener
-
public class RunListener extends java.lang.ObjectIf you need to respond to the events during a test run, extend
RunListenerand 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
Cowbellclass 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); }- Since:
- 4.0
- See Also:
JUnitCore
-
-
Constructor Summary
Constructors Constructor Description RunListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidtestAssumptionFailure(Failure failure)Called when an atomic test flags that it assumes a condition that is falsevoidtestFailure(Failure failure)Called when an atomic test fails.voidtestFinished(Description description)Called when an atomic test has finished, whether the test succeeds or fails.voidtestIgnored(Description description)Called when a test will not be run, generally because a test method is annotated withIgnore.voidtestRunFinished(Result result)Called when all tests have finishedvoidtestRunStarted(Description description)Called before any tests have been run.voidtestStarted(Description description)Called when an atomic test is about to be started.
-
-
-
Method Detail
-
testRunStarted
public void testRunStarted(Description description) throws java.lang.Exception
Called before any tests have been run.- Parameters:
description- describes the tests to be run- Throws:
java.lang.Exception
-
testRunFinished
public void testRunFinished(Result result) throws java.lang.Exception
Called when all tests have finished- Parameters:
result- the summary of the test run, including all the tests that failed- Throws:
java.lang.Exception
-
testStarted
public void testStarted(Description description) throws java.lang.Exception
Called when an atomic test is about to be started.- Parameters:
description- the description of the test that is about to be run (generally a class and method name)- Throws:
java.lang.Exception
-
testFinished
public void testFinished(Description description) throws java.lang.Exception
Called when an atomic test has finished, whether the test succeeds or fails.- Parameters:
description- the description of the test that just ran- Throws:
java.lang.Exception
-
testFailure
public void testFailure(Failure failure) throws java.lang.Exception
Called when an atomic test fails.- Parameters:
failure- describes the test that failed and the exception that was thrown- Throws:
java.lang.Exception
-
testAssumptionFailure
public void testAssumptionFailure(Failure failure)
Called when an atomic test flags that it assumes a condition that is false- Parameters:
failure- describes the test that failed and theAssumptionViolatedExceptionthat was thrown
-
testIgnored
public void testIgnored(Description description) throws java.lang.Exception
Called when a test will not be run, generally because a test method is annotated withIgnore.- Parameters:
description- describes the test that will not be run- Throws:
java.lang.Exception
-
-