# TestOptions

# TestOptions

```
@Incubating interface TestOptions
```

|----------------------------------------------------------------------------------------------------------------------------------------------|
| [com.android.build.api.dsl.TestOptions](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#) |

Options for running tests.

## Summary

|                                                                                                                                                                                                                                               ### Public methods                                                                                                                                                                                                                                                ||
|--------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [emulatorSnapshots](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#emulatorSnapshots(kotlin.Function1))`(`action:` `[EmulatorSnapshots](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/EmulatorSnapshots).()` `->` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` <br />                    |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [failureRetention](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#failureRetention(kotlin.Function1))`(`action:` `[FailureRetention](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/FailureRetention).()` `->` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` <br />                        |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [unitTests](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#unitTests(kotlin.Function1))`(`action:` `[UnitTestOptions](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/UnitTestOptions).()` `->` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` Options for controlling unit tests execution. |

|                                                                                                                                                                                                                                                                  ### Properties                                                                                                                                                                                                                                                                   ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)                                                                                                                                                                              | [animationsDisabled](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#animationsDisabled:kotlin.Boolean) Disables animations during instrumented tests you run from the command line.                                  |
| abstract[NamedDomainObjectContainer](https://docs.gradle.org/current/javadoc/org/gradle/api/NamedDomainObjectContainer.html)\<[DeviceGroup](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/DeviceGroup)\>                       | [deviceGroups](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#deviceGroups:org.gradle.api.NamedDomainObjectContainer) List of DeviceGroups that can be run through connected check, using the Unified Test Platform. |
| abstract[ExtensiblePolymorphicDomainObjectContainer](https://docs.gradle.org/current/javadoc/org/gradle/api/ExtensiblePolymorphicDomainObjectContainer.html)\<[Device](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/Device)\> | [devices](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#devices:org.gradle.api.ExtensiblePolymorphicDomainObjectContainer) List of test devices for this project for use with the Unified Test Platform             |
| abstract[EmulatorSnapshots](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/EmulatorSnapshots)                                                                                                                                   | [emulatorSnapshots](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#emulatorSnapshots:com.android.build.api.dsl.EmulatorSnapshots) Configures Android Test Retention.                                                 |
| abstract[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)                                                                                                                                                                                | [execution](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#execution:kotlin.String) Specifies whether to use on-device test orchestration.                                                                           |
| abstract[FailureRetention](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/FailureRetention)                                                                                                                                     | [failureRetention](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#failureRetention:com.android.build.api.dsl.FailureRetention) <br />                                                                                |
| abstract[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?                                                                                                                                                                               | [reportDir](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#reportDir:kotlin.String) Name of the reports directory.                                                                                                   |
| abstract[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?                                                                                                                                                                               | [resultsDir](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#resultsDir:kotlin.String) Name of the results directory.                                                                                                 |
| abstract[UnitTestOptions](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/UnitTestOptions)                                                                                                                                       | [unitTests](https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/TestOptions#unitTests:com.android.build.api.dsl.UnitTestOptions) Options for controlling unit tests execution.                                                        |

## Public methods

### emulatorSnapshots

```
abstract fun emulatorSnapshots(action: EmulatorSnapshots.() -> Unit): Unit
```  

### failureRetention

```
abstract fun failureRetention(action: FailureRetention.() -> Unit): Unit
```

**Deprecated.**  

### unitTests

```
abstract fun unitTests(action: UnitTestOptions.() -> Unit): Unit
```

Options for controlling unit tests execution.

## Properties

### animationsDisabled

```
abstract var animationsDisabled: Boolean
```

Disables animations during instrumented tests you run from the command line.

If you set this property to`true`, running instrumented tests with Gradle from the command line executes`am instrument`with the`--no-window-animation`flag. By default, this property is set to`false`.

This property does not affect tests that you run using Android Studio. To learn more about running tests from the command line, see[Test from the Command Line](https://d.android.com/studio/test/command-line.html).  

### deviceGroups

```
abstract val deviceGroups: NamedDomainObjectContainer<DeviceGroup>
```

List of DeviceGroups that can be run through connected check, using the Unified Test Platform.

DeviceGroups with individual devices are added automatically, with the same name of the individual device.

These APIs are experimental and may change without notice.  

### devices

```
abstract val devices: ExtensiblePolymorphicDomainObjectContainer<Device>
```

List of test devices for this project for use with the Unified Test Platform

These APIs are experimental and may change without notice.  

### emulatorSnapshots

```
abstract val emulatorSnapshots: EmulatorSnapshots
```

Configures Android Test Retention.

Android Test Retention automatically takes emulator snapshots on test failures. It can only work with Unified Test Platform (UTP).  

```text
android {
  testOptions {
    emulatorSnapshots {
      enableForTestFailures true
      maxSnapshotsForTestFailures 2
      compressSnapshots false
    }
  }
}
```  

### execution

Added in[API level 3.0.0](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract var execution: String
```

Specifies whether to use on-device test orchestration.

If you want to[use Android Test Orchestrator](https://developer.android.com/training/testing/junit-runner.html#using-android-test-orchestrator)you need to specify`"ANDROID_TEST_ORCHESTRATOR"`, as shown below. By default, this property is set to`"HOST"`, which disables on-device orchestration.  

```scdoc
android {
  testOptions {
    execution 'ANDROID_TEST_ORCHESTRATOR'
  }
}
```  

### failureRetention

```
abstract val failureRetention: FailureRetention
```

**Deprecated.**  

### reportDir

```
abstract var reportDir: String?
```

Name of the reports directory.  

### resultsDir

```
abstract var resultsDir: String?
```

Name of the results directory.  

### unitTests

```
abstract val unitTests: UnitTestOptions
```

Options for controlling unit tests execution.