DisableOnAndroidDebug

public class DisableOnAndroidDebug
extends Object implements TestRule

java.lang.Object
   ↳ android.support.test.rule.DisableOnAndroidDebug


DisableOnAndroidDebug规则允许您在调试时标记某些要禁用的规则。

最具说明性的用例是针对使用Timeout规则的测试,在调试模式下运行时,测试可能在调试期间突然终止超时。 开发人员可以通过在需要调试的测试上更改代码并记住恢复更改,或者可以在调试期间禁用的规则(如Timeout可以封装在DisableOnDebug ,从而禁用超时或增加超时。

此功能的重要好处是,您可以禁用此类规则,而无需对测试类进行任何修改,以便在调试过程中将其删除。

这在调试时没有处理超时或时间敏感的代码,并且在这种情况下可能会使它不那么有用。

用法示例:

 public static class DisableTimeoutOnDebugSampleTest {

     @Rule
     public TestRule timeout = new DisableOnAndroidDebug(new Timeout(20));

     @Test
     public void myTest() {
         int i = 0;
         assertEquals(0, i); // suppose you had a break point here to inspect i
     }
 }
 

Summary

Public constructors

DisableOnAndroidDebug(TestRule rule)

将另一个 TestRuleTestRule并在连接调试器时有条件地将其禁用。

Public methods

final Statement apply(Statement base, Description description)

boolean isDebugging()

如果虚拟机连接了调试器,则返回 true

Inherited methods

From class java.lang.Object
From interface org.junit.rules.TestRule

Public constructors

DisableOnAndroidDebug

DisableOnAndroidDebug (TestRule rule)

将另一个 TestRuleTestRule并在连接调试器时有条件地将其禁用。

Parameters
rule TestRule: to disable during debugging

Public methods

apply

Statement apply (Statement base, 
                Description description)

Parameters
base Statement
description 描述
Returns
Statement

isDebugging

boolean isDebugging ()

Returns true if the VM has a debugger connected. This method may be used by test classes to take additional action to disable code paths that interfere with debugging if required.

Returns
boolean true if a debugger is connected, false otherwise