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 {
@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
}
}
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.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# DisableOnAndroidDebug\n\nSummary: [Ctors](#pubctors) \\| [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \\| [\\[Expand All\\]](#) \n\nDisableOnAndroidDebug\n=====================\n\n| This package is part of the Android [support library](/topic/libraries/support-library) which is no longer maintained. The support library has been superseded by [AndroidX](/jetpack/androidx) which is part of [Jetpack](/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider [migrating](/jetpack/androidx/migrate) existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library [class\n| mappings](/jetpack/androidx/migrate/class-mappings).\n\n\n`\npublic\n\n\nclass\nDisableOnAndroidDebug\n`\n\n\n`\n\nextends `[Object](https://developer.android.com/reference/java/lang/Object.html)`\n\n\n`\n\n`\n\n\nimplements\n\nTestRule\n\n\n`\n\n|---|-------------------------------------------------|\n| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||\n| ↳ | android.support.test.rule.DisableOnAndroidDebug |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nThe `DisableOnAndroidDebug` Rule allows you to label certain rules to be disabled when\ndebugging.\n\nThe most illustrative use case is for tests that make use of the [`Timeout`](http://junit.org/apidocs/org/junit/rules/Timeout.html) rule, when\nran in debug mode the test may terminate on timeout abruptly during debugging. Developers may\ndisable the timeout, or increase the timeout by making a code change on tests that need debugging\nand remember revert the change afterwards or rules such as [`Timeout`](http://junit.org/apidocs/org/junit/rules/Timeout.html) that may be\ndisabled during debugging may be wrapped in a `DisableOnDebug`.\n\nThe important benefit of this feature is that you can disable such rules without any making\nany modifications to your test class to remove them during debugging.\n\nThis does nothing to tackle timeouts or time sensitive code under test when debugging and may\nmake this less useful in such circumstances.\n\nExample usage:\n\n```\n public static class DisableTimeoutOnDebugSampleTest {\n\n @Rule\n public TestRule timeout = new DisableOnAndroidDebug(new Timeout(20));\n\n @Test\n public void myTest() {\n int i = 0;\n assertEquals(0, i); // suppose you had a break point here to inspect i\n }\n }\n \n```\n\n\u003cbr /\u003e\n\nSummary\n-------\n\n| ### Public constructors ||\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| ` `[DisableOnAndroidDebug](/reference/android/support/test/rule/DisableOnAndroidDebug#DisableOnAndroidDebug(org.junit.rules.TestRule))`(TestRule rule) ` Wrap another [TestRule](/reference/org/junit/rules/TestRule) and conditionally disable it when a debugger is attached. |\n\n| ### Public methods ||\n|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` final Statement` | ` `[apply](/reference/android/support/test/rule/DisableOnAndroidDebug#apply(org.junit.runners.model.Statement, org.junit.runner.Description))`(Statement base, Description description) ` |\n| ` boolean` | ` `[isDebugging](/reference/android/support/test/rule/DisableOnAndroidDebug#isDebugging())`() ` Returns `true` if the VM has a debugger connected. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)` ` |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object.html) | ` clone() ` | | ` boolean` | ` equals(`[Object](https://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void` | ` finalize() ` | | ` final `[Class](https://developer.android.com/reference/java/lang/Class.html)`\u003c?\u003e` | ` getClass() ` | | ` int` | ` hashCode() ` | | ` final void` | ` notify() ` | | ` final void` | ` notifyAll() ` | | ` `[String](https://developer.android.com/reference/java/lang/String.html) | ` toString() ` | | ` final void` | ` wait(long arg0, int arg1) ` | | ` final void` | ` wait(long arg0) ` | | ` final void` | ` wait() ` | ||\n| From interface ` org.junit.rules.TestRule ` |-----------------------|---------------------------------------------| | ` abstract Statement` | ` apply(Statement arg0, Description arg1) ` | ||\n\nPublic constructors\n-------------------\n\n### DisableOnAndroidDebug\n\n```\nDisableOnAndroidDebug (TestRule rule)\n```\n\nWrap another [TestRule](/reference/org/junit/rules/TestRule) and conditionally disable it when a debugger is attached.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|--------|------------------------------------------------|\n| `rule` | `TestRule`: to disable during debugging \u003cbr /\u003e |\n\nPublic methods\n--------------\n\n### apply\n\n```\nStatement apply (Statement base, \n Description description)\n```\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------------|----------------------|\n| `base` | `Statement` \u003cbr /\u003e |\n| `description` | `Description` \u003cbr /\u003e |\n\n| Returns ||\n|-------------|--------|\n| `Statement` | \u003cbr /\u003e |\n\n### isDebugging\n\n```\nboolean isDebugging ()\n```\n\nReturns `true` if the VM has a debugger connected. This method may be used by test\nclasses to take additional action to disable code paths that interfere with debugging if\nrequired.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-----------|-------------------------------------------------------------|\n| `boolean` | `true` if a debugger is connected, `false` otherwise \u003cbr /\u003e |\n\n-\n\n Classes\n -------\n\n - [ActivityTestRule](/reference/android/support/test/rule/ActivityTestRule)\n - [DisableOnAndroidDebug](/reference/android/support/test/rule/DisableOnAndroidDebug)\n - [GrantPermissionRule](/reference/android/support/test/rule/GrantPermissionRule)\n - [ServiceTestRule](/reference/android/support/test/rule/ServiceTestRule)\n - [UiThreadTestRule](/reference/android/support/test/rule/UiThreadTestRule)"]]