类 RunListener
- java.lang.Object
- org.junit.runner.notification.RunListener
- 直接已知子类:
TextListener
public class RunListener extends Object
Register an instance of this class withRunNotifier
to be notified of events that occur during a test run. All of the methods in this class are abstract and have no implementation; override one or more methods to receive events.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
testFailure(Failure)
called with aDescription
ofDescription.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
RunListener.ThreadSafe
.Listener methods will be called from the same thread as is running the test, unless otherwise indicated by the method Javadoc
- 从以下版本开始:
- 4.0
- 另请参阅:
JUnitCore
嵌套类概要
嵌套类 修饰符和类型 类 说明 static interface
RunListener.ThreadSafe
Indicates aRunListener
that can have its methods called concurrently.
构造器概要
构造器 构造器 说明 RunListener()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
testAssumptionFailure(Failure failure)
Called when an atomic test flags that it assumes a condition that is falsevoid
testFailure(Failure failure)
Called when an atomic test fails, or when a listener throws an exception.void
testFinished(Description description)
Called when an atomic test has finished, whether the test succeeds or fails.void
testIgnored(Description description)
Called when a test will not be run, generally because a test method is annotated withIgnore
.void
testRunFinished(Result result)
Called when all tests have finished.void
testRunStarted(Description description)
Called before any tests have been run.void
testStarted(Description description)
Called when an atomic test is about to be started.
构造器详细资料
RunListener
public RunListener()
方法详细资料
testRunStarted
public void testRunStarted(Description description) throws Exception
Called before any tests have been run. This may be called on an arbitrary thread.- 参数:
description
- describes the tests to be run- 抛出:
Exception
testRunFinished
public void testRunFinished(Result result) throws Exception
Called when all tests have finished. This may be called on an arbitrary thread.- 参数:
result
- the summary of the test run, including all the tests that failed- 抛出:
Exception
testStarted
public void testStarted(Description description) throws Exception
Called when an atomic test is about to be started.- 参数:
description
- the description of the test that is about to be run (generally a class and method name)- 抛出:
Exception
testFinished
public void testFinished(Description description) throws Exception
Called when an atomic test has finished, whether the test succeeds or fails.- 参数:
description
- the description of the test that just ran- 抛出:
Exception
testFailure
public void testFailure(Failure failure) throws Exception
Called when an atomic test fails, or when a listener throws an exception.In the case of a failure of an atomic test, this method will be called with the same
Description
passed totestStarted(Description)
, from the same thread that calledtestStarted(Description)
.In the case of a listener throwing an exception, this will be called with a
Description
ofDescription.TEST_MECHANISM
, and may be called on an arbitrary thread.- 参数:
failure
- describes the test that failed and the exception that was thrown- 抛出:
Exception
testAssumptionFailure
public void testAssumptionFailure(Failure failure)
Called when an atomic test flags that it assumes a condition that is false- 参数:
failure
- describes the test that failed and theAssumptionViolatedException
that was thrown
testIgnored
public void testIgnored(Description description) throws Exception
Called when a test will not be run, generally because a test method is annotated withIgnore
.- 参数:
description
- describes the test that will not be run- 抛出:
Exception