程序包 org.junit.rules
类 DisableOnDebug
- java.lang.Object
- org.junit.rules.DisableOnDebug
- 所有已实现的接口:
TestRule
public class DisableOnDebug extends Object implements TestRule
TheDisableOnDebug
Rule allows you to label certain rules to be disabled when debugging.The most illustrative use case is for tests that make use of the
Timeout
rule, when ran in debug mode the test may terminate on timeout abruptly during debugging. Developers may disable the timeout, or increase the timeout by making a code change on tests that need debugging and remember revert the change afterwards or rules such asTimeout
that may be disabled during debugging may be wrapped in aDisableOnDebug
.The important benefit of this feature is that you can disable such rules without any making any modifications to your test class to remove them during debugging.
This does nothing to tackle timeouts or time sensitive code under test when debugging and may make this less useful in such circumstances.
Example usage:
public static class DisableTimeoutOnDebugSampleTest { @Rule public TestRule timeout = new DisableOnDebug(new Timeout(20)); @Test public void myTest() { int i = 0; assertEquals(0, i); // suppose you had a break point here to inspect i } }
- 从以下版本开始:
- 4.12
构造器概要
构造器 构造器 说明 DisableOnDebug(TestRule rule)
Create aDisableOnDebug
instance with the timeout specified in milliseconds.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 Statement
apply(Statement base, Description description)
Modifies the method-runningStatement
to implement this test-running rule.boolean
isDebugging()
Returnstrue
if the JVM is in debug mode.
构造器详细资料
DisableOnDebug
public DisableOnDebug(TestRule rule)
Create aDisableOnDebug
instance with the timeout specified in milliseconds.- 参数:
rule
- to disable during debugging
方法详细资料
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. - 另请参阅:
TestRule.apply(Statement, Description)
isDebugging
public boolean isDebugging()
Returnstrue
if the JVM is in debug mode. This method may be used by test classes to take additional action to disable code paths that interfere with debugging if required.- 返回:
true
if the current JVM is in debug mode,false
otherwise