# TestOptions

# TestOptions

[View Source](https://cs.android.com/search?q=file:com/android/build/api/dsl/TestOptions.kt+class:com.android.build.api.dsl.TestOptions)  
Added in 4.2.0  

<br />

```
interface TestOptions
```

<br />

*** ** * ** ***

Options for running tests.

## Summary

|                             ### Public functions                             |
|------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `@`[Incubating](https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html) [emulatorControl](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#emulatorControl(kotlin.Function1))`(action: `[EmulatorControl](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/EmulatorControl)`.() `->` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)`                                                                                  |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `@`[Incubating](https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html) [emulatorSnapshots](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#emulatorSnapshots(kotlin.Function1))`(action: `[EmulatorSnapshots](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/EmulatorSnapshots)`.() `->` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)`                                                                          |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `@`[Incubating](https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html) ~~[failureRetention](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#failureRetention(kotlin.Function1))~~`(action: `[FailureRetention](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/FailureRetention)`.() `->` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` **This function is deprecated.**Renamed to emulatorSnapshots             |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `@`[Incubating](https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html) [managedDevices](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#managedDevices(kotlin.Function1))`(action: `[ManagedDevices](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/ManagedDevices)`.() `->` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` Configures Gradle Managed Devices for use in testing with the Unified test platform. |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [unitTests](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#unitTests(kotlin.Function1))`(action: `[UnitTestOptions](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/UnitTestOptions)`.() `->` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` Options for controlling unit tests execution.                                                                                                                                        |

|                                                                                                                       ### Public properties                                                                                                                       |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)                                                                                                                                                                                | [animationsDisabled](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#animationsDisabled()) Disables animations during instrumented tests you run from the command line.                     |
| [NamedDomainObjectContainer](https://docs.gradle.org/current/javadoc/org/gradle/api/NamedDomainObjectContainer.html)`<`[DeviceGroup](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/DeviceGroup)`>`                       | [deviceGroups](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#deviceGroups()) **This property is deprecated.**deviceGroups is deprecated in testOptions, use managedDevices.groups instead |
| [ExtensiblePolymorphicDomainObjectContainer](https://docs.gradle.org/current/javadoc/org/gradle/api/ExtensiblePolymorphicDomainObjectContainer.html)`<`[Device](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/Device)`>` | [devices](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#devices()) **This property is deprecated.**devices is deprecated in testOptions, use managedDevices.devices instead               |
| [EmulatorControl](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/EmulatorControl)                                                                                                                                         | [emulatorControl](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#emulatorControl()) Configures Android Emulator Grpc Access                                                                |
| [EmulatorSnapshots](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/EmulatorSnapshots)                                                                                                                                     | [emulatorSnapshots](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#emulatorSnapshots()) Configures Android Test Retention.                                                                 |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)                                                                                                                                                                                  | [execution](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#execution()) Specifies whether to use on-device test orchestration.                                                             |
| [FailureRetention](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/FailureRetention)                                                                                                                                       | [failureRetention](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#failureRetention()) **This property is deprecated.**Renamed to emulatorSnapshots                                         |
| [ManagedDevices](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/ManagedDevices)                                                                                                                                           | [managedDevices](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#managedDevices()) Configures Gradle Managed Devices for use in testing with the Unified test platform.                     |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?`                                                                                                                                                                               | [reportDir](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#reportDir()) Name of the reports directory.                                                                                     |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?`                                                                                                                                                                               | [resultsDir](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#resultsDir()) Name of the results directory.                                                                                   |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`?`                                                                                                                                                                                     | [targetSdk](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#targetSdk()) Specifies value that overrides target sdk version number for tests in libraries.                                   |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?`                                                                                                                                                                               | [targetSdkPreview](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#targetSdkPreview()) Specifies value that overrides target sdk preview number for tests in libraries.                     |
| [UnitTestOptions](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/UnitTestOptions)                                                                                                                                         | [unitTests](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#unitTests()) Options for controlling unit tests execution.                                                                      |

## Public functions

### emulatorControl

Added in 8.1.0  

```
@Incubating
fun emulatorControl(action: EmulatorControl.() -> Unit): Unit
```  

### emulatorSnapshots

Added in 7.0.0  

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

### failureRetention

Added in 7.0.0  
Deprecated in 7.0.0  

```
@Incubating
fun [failureRetention](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#failureRetention(kotlin.Function1))(action: FailureRetention.() -> Unit): Unit
```
| **This function is deprecated.**   
Renamed to emulatorSnapshots  

### managedDevices

Added in 7.2.0  

```
@Incubating
fun managedDevices(action: ManagedDevices.() -> Unit): Unit
```

Configures Gradle Managed Devices for use in testing with the Unified test platform.  

### unitTests

Added in 4.2.0  

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

Options for controlling unit tests execution.  

## Public properties

### animationsDisabled

Added in 4.2.0  

```
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

Added in 4.2.0  
Deprecated in 7.3.0  

```
val deviceGroups: NamedDomainObjectContainer<DeviceGroup>
```
| **This property is deprecated.**   
| deviceGroups is deprecated in testOptions, use managedDevices.groups instead

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.

[deviceGroups](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#deviceGroups())is deprecated, use managedDevices.groups to specify groups of Gradle Managed Devices.  

### devices

Added in 4.2.0  
Deprecated in 7.3.0  

```
val devices: ExtensiblePolymorphicDomainObjectContainer<Device>
```
| **This property is deprecated.**   
| devices is deprecated in testOptions, use managedDevices.devices instead

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

These APIs are experimental and may change without notice.

[devices](https://developer.android.com/reference/tools/gradle-api/8.4/com/android/build/api/dsl/TestOptions#devices())is deprecated, use managedDevices.devices to specify Gradle Managed Devices  

### emulatorControl

Added in 8.1.0  

```
val emulatorControl: EmulatorControl
```

Configures Android Emulator Grpc Access

Android Emulator Grpc Access will make it possible to interact with the emulator over gRPC  

```text
android {
    emulatorControl {
      enable true
      secondsValid 180
      allowedEndpoints.addAll(
          "/android.emulation.control.EmulatorController/getStatus",
          "/android.emulation.control.EmulatorController/getVmState")
    }
}
```  

### emulatorSnapshots

Added in 7.0.0  

```
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 4.2.0  

```
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'
  }
}
```

since 3.0.0  

### failureRetention

Added in 4.2.0  
Deprecated in 7.0.0  

```
val failureRetention: FailureRetention
```
| **This property is deprecated.**   
Renamed to emulatorSnapshots  

### managedDevices

Added in 7.2.0  

```
val managedDevices: ManagedDevices
```

Configures Gradle Managed Devices for use in testing with the Unified test platform.  

### reportDir

Added in 4.2.0  

```
var reportDir: String?
```

Name of the reports directory.  

### resultsDir

Added in 4.2.0  

```
var resultsDir: String?
```

Name of the results directory.  

### targetSdk

Added in 8.2.0-beta03  

```
var targetSdk: Int?
```

Specifies value that overrides target sdk version number for tests in libraries. Default value is set to minSdk. Important: Setting this value will cause an error for application and other module types.  

### targetSdkPreview

Added in 8.2.0-beta03  

```
var targetSdkPreview: String?
```

Specifies value that overrides target sdk preview number for tests in libraries. Default value is empty. Important: Setting this value will cause an error for application and other module types.  

### unitTests

Added in 4.2.0  

```
val unitTests: UnitTestOptions
```

Options for controlling unit tests execution.