程序包 org.junit.rules
类 TestWatcher
- java.lang.Object
- org.junit.rules.TestWatcher
- 所有已实现的接口:
TestRule
- 直接已知子类:
TestName
public abstract class TestWatcher extends Object implements TestRule
TestWatcher is a base class for Rules that take note of the testing action, without modifying it. For example, this class will keep a log of each passing and failing test:public static class WatchmanTest { private static String watchedLog; @Rule public TestWatcher watchman= new TestWatcher() { @Override protected void failed(Throwable e, Description description) { watchedLog+= description + "\n"; } @Override protected void succeeded(Description description) { watchedLog+= description + " " + "success!\n"; } }; @Test public void fails() { fail(); } @Test public void succeeds() { } }
- 从以下版本开始:
- 4.9
构造器概要
构造器 构造器 说明 TestWatcher()
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 Statement
apply(Statement base, Description description)
Modifies the method-runningStatement
to implement this test-running rule.protected void
failed(Throwable e, Description description)
Invoked when a test failsprotected void
finished(Description description)
Invoked when a test method finishes (whether passing or failing)protected void
skipped(AssumptionViolatedException e, Description description)
Invoked when a test is skipped due to a failed assumption.protected void
skipped(AssumptionViolatedException e, Description description)
protected void
starting(Description description)
Invoked when a test is about to startprotected void
succeeded(Description description)
Invoked when a test succeeds
构造器详细资料
TestWatcher
public TestWatcher()
方法详细资料
apply
public Statement apply(Statement base, Description description)
从接口复制的说明:TestRule
Modifies the method-runningStatement
to implement this test-running rule.- 指定者:
apply
在接口中TestRule
- 参数:
base
- TheStatement
to be modifieddescription
- ADescription
of the test implemented inbase
- 返回:
- a new statement, which may be the same as
base
, a wrapper aroundbase
, or a completely new Statement.
succeeded
protected void succeeded(Description description)
Invoked when a test succeeds
failed
protected void failed(Throwable e, Description description)
Invoked when a test fails
skipped
protected void skipped(AssumptionViolatedException e, Description description)
Invoked when a test is skipped due to a failed assumption.
skipped
@Deprecated protected void skipped(AssumptionViolatedException e, Description description)
Invoked when a test is skipped due to a failed assumption.
starting
protected void starting(Description description)
Invoked when a test is about to start
finished
protected void finished(Description description)
Invoked when a test method finishes (whether passing or failing)