# DisableOnAndroidDebug

# DisableOnAndroidDebug

Artifact:[androidx.test:rules](https://developer.android.com/jetpack/androidx/releases/test)  
[View Source](https://cs.android.com/search?q=file:androidx/test/rule/DisableOnAndroidDebug.java+class:androidx.test.rule.DisableOnAndroidDebug)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/test/rule/DisableOnAndroidDebug "View this page in Java")

<br />

```
class DisableOnAndroidDebug : TestRule
```

<br />

*** ** * ** ***

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[org.junit.rules.Timeout](https://junit.org/junit4/javadoc/4.12/org/junit/rules/Timeout.html)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[org.junit.rules.Timeout](https://junit.org/junit4/javadoc/4.12/org/junit/rules/Timeout.html)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:  

```kotlin
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](https://developer.android.com/reference/kotlin/androidx/test/rule/DisableOnAndroidDebug#DisableOnAndroidDebug(org.junit.rules.TestRule))`(rule: `[TestRule](https://junit.org/junit4/javadoc/4.12/org/junit/rules/TestRule.html)`!)` Wrap another[TestRule](https://junit.org/junit4/javadoc/4.12/org/junit/rules/TestRule.html)and conditionally disable it when a debugger is attached. |

|                                     ### Public functions                                     |
|----------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Statement](https://junit.org/junit4/javadoc/4.12/org/junit/runners/model/Statement.html)`!` | [apply](https://developer.android.com/reference/kotlin/androidx/test/rule/DisableOnAndroidDebug#apply(org.junit.runners.model.Statement,org.junit.runner.Description))`(base: `[Statement](https://junit.org/junit4/javadoc/4.12/org/junit/runners/model/Statement.html)`!, description: `[Description](https://junit.org/junit4/javadoc/4.12/org/junit/runner/Description.html)`!)` |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)          | [isDebugging](https://developer.android.com/reference/kotlin/androidx/test/rule/DisableOnAndroidDebug#isDebugging())`()` Returns`true`if the VM has a debugger connected.                                                                                                                                                                                                            |

## Public constructors

### DisableOnAndroidDebug

```
DisableOnAndroidDebug(rule: TestRule!)
```

Wrap another[TestRule](https://junit.org/junit4/javadoc/4.12/org/junit/rules/TestRule.html)and conditionally disable it when a debugger is attached.  

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|-----------------------------|
| `rule: `[TestRule](https://junit.org/junit4/javadoc/4.12/org/junit/rules/TestRule.html)`!` | to disable during debugging |

## Public functions

### apply

```
fun apply(base: Statement!, description: Description!): Statement!
```  

### isDebugging

```
fun isDebugging(): Boolean
```

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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`if a debugger is connected,`false`otherwise |