Skip to content

Most visited

Recently visited



public class DisableOnAndroidDebug
extends Object implements TestRule


The DisableOnAndroidDebug 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 as Timeout that may be disabled during debugging may be wrapped in a DisableOnDebug.

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 {

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

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


Public constructors

DisableOnAndroidDebug(TestRule rule)

Wrap another TestRule and conditionally disable it when a debugger is attached.

Public methods

final Statement apply(Statement base, Description description)

boolean isDebugging()

Returns true if the VM has a debugger connected.

Inherited methods

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

Public constructors


DisableOnAndroidDebug (TestRule rule)

Wrap another TestRule and conditionally disable it when a debugger is attached.

rule TestRule: to disable during debugging

Public methods


Statement apply (Statement base, 
                Description description)

base Statement

description Description



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.

boolean true if a debugger is connected, false otherwise

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)