Stay organized with collections
Save and categorize content based on your preferences.
TestOptions
@Incubating interface TestOptions
Options for running tests.
Summary
Public methods
|
abstract Unit |
|
abstract Unit |
|
abstract Unit |
Options for controlling unit tests execution.
|
Public methods
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.
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.
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).
android {
testOptions {
emulatorSnapshots {
enableForTestFailures true
maxSnapshotsForTestFailures 2
compressSnapshots false
}
}
}
execution
abstract var execution: String
Specifies whether to use on-device test orchestration.
If you want to use 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.
android {
testOptions {
execution 'ANDROID_TEST_ORCHESTRATOR'
}
}
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.
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.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# TestOptions\n===========\n\n```\n@Incubating interface TestOptions\n```\n\n|--------------------------------------------|\n| [com.android.build.api.dsl.TestOptions](#) |\n\nOptions for running tests.\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [emulatorSnapshots](#emulatorSnapshots(kotlin.Function1))`(`action:` `[EmulatorSnapshots](/reference/tools/gradle-api/7.0/com/android/build/api/dsl/EmulatorSnapshots).()` `-\u003e` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` \u003cbr /\u003e |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [failureRetention](#failureRetention(kotlin.Function1))`(`action:` `[FailureRetention](/reference/tools/gradle-api/7.0/com/android/build/api/dsl/FailureRetention).()` `-\u003e` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` \u003cbr /\u003e |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [unitTests](#unitTests(kotlin.Function1))`(`action:` `[UnitTestOptions](/reference/tools/gradle-api/7.0/com/android/build/api/dsl/UnitTestOptions).()` `-\u003e` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` Options for controlling unit tests execution. |\n\n| ### Properties ||\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [animationsDisabled](#animationsDisabled:kotlin.Boolean) Disables animations during instrumented tests you run from the command line. |\n| abstract [NamedDomainObjectContainer](https://docs.gradle.org/current/javadoc/org/gradle/api/NamedDomainObjectContainer.html)\\\u003c[DeviceGroup](/reference/tools/gradle-api/7.0/com/android/build/api/dsl/DeviceGroup)\\\u003e | [deviceGroups](#deviceGroups:org.gradle.api.NamedDomainObjectContainer) List of DeviceGroups that can be run through connected check, using the Unified Test Platform. |\n| abstract [ExtensiblePolymorphicDomainObjectContainer](https://docs.gradle.org/current/javadoc/org/gradle/api/ExtensiblePolymorphicDomainObjectContainer.html)\\\u003c[Device](/reference/tools/gradle-api/7.0/com/android/build/api/dsl/Device)\\\u003e | [devices](#devices:org.gradle.api.ExtensiblePolymorphicDomainObjectContainer) List of test devices for this project for use with the Unified Test Platform |\n| abstract [EmulatorSnapshots](/reference/tools/gradle-api/7.0/com/android/build/api/dsl/EmulatorSnapshots) | [emulatorSnapshots](#emulatorSnapshots:com.android.build.api.dsl.EmulatorSnapshots) Configures Android Test Retention. |\n| abstract [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | [execution](#execution:kotlin.String) Specifies whether to use on-device test orchestration. |\n| abstract [FailureRetention](/reference/tools/gradle-api/7.0/com/android/build/api/dsl/FailureRetention) | [failureRetention](#failureRetention:com.android.build.api.dsl.FailureRetention) \u003cbr /\u003e |\n| abstract [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)? | [reportDir](#reportDir:kotlin.String) Name of the reports directory. |\n| abstract [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)? | [resultsDir](#resultsDir:kotlin.String) Name of the results directory. |\n| abstract [UnitTestOptions](/reference/tools/gradle-api/7.0/com/android/build/api/dsl/UnitTestOptions) | [unitTests](#unitTests:com.android.build.api.dsl.UnitTestOptions) Options for controlling unit tests execution. |\n\nPublic methods\n--------------\n\n### emulatorSnapshots\n\n```\nabstract fun emulatorSnapshots(action: EmulatorSnapshots.() -\u003e Unit): Unit\n``` \n\n### failureRetention\n\n```\nabstract fun failureRetention(action: FailureRetention.() -\u003e Unit): Unit\n```\n\n**Deprecated.** \n\n### unitTests\n\n```\nabstract fun unitTests(action: UnitTestOptions.() -\u003e Unit): Unit\n```\n\nOptions for controlling unit tests execution.\n\nProperties\n----------\n\n### animationsDisabled\n\n```\nabstract var animationsDisabled: Boolean\n```\n\nDisables animations during instrumented tests you run from the command line.\n\nIf you set this property to `true`, running instrumented tests with Gradle from the command\nline executes `am instrument` with the `--no-window-animation` flag.\nBy default, this property is set to `false`.\n\nThis property does not affect tests that you run using Android Studio. To learn more about\nrunning tests from the command line, see\n[Test from the Command Line](https://d.android.com/studio/test/command-line.html). \n\n### deviceGroups\n\n```\nabstract val deviceGroups: NamedDomainObjectContainer\u003cDeviceGroup\u003e\n```\n\nList of DeviceGroups that can be run through connected check, using the Unified Test\nPlatform.\n\nDeviceGroups with individual devices are added automatically, with the same name of the\nindividual device.\n\nThese APIs are experimental and may change without notice. \n\n### devices\n\n```\nabstract val devices: ExtensiblePolymorphicDomainObjectContainer\u003cDevice\u003e\n```\n\nList of test devices for this project for use with the Unified Test Platform\n\nThese APIs are experimental and may change without notice. \n\n### emulatorSnapshots\n\n```\nabstract val emulatorSnapshots: EmulatorSnapshots\n```\n\nConfigures Android Test Retention.\n\nAndroid Test Retention automatically takes emulator snapshots on test failures. It can only\nwork with Unified Test Platform (UTP). \n\n```text\nandroid {\n testOptions {\n emulatorSnapshots {\n enableForTestFailures true\n maxSnapshotsForTestFailures 2\n compressSnapshots false\n }\n }\n}\n``` \n\n### execution\n\nAdded in [API level 3.0.0](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract var execution: String\n```\n\nSpecifies whether to use on-device test orchestration.\n\nIf you want to [use Android Test Orchestrator](https://developer.android.com/training/testing/junit-runner.html#using-android-test-orchestrator)\nyou need to specify `\"ANDROID_TEST_ORCHESTRATOR\"`, as shown below.\nBy default, this property is set to `\"HOST\"`, which disables on-device orchestration. \n\n```scdoc\nandroid {\n testOptions {\n execution 'ANDROID_TEST_ORCHESTRATOR'\n }\n}\n``` \n\n### failureRetention\n\n```\nabstract val failureRetention: FailureRetention\n```\n\n**Deprecated.** \n\n### reportDir\n\n```\nabstract var reportDir: String?\n```\n\nName of the reports directory. \n\n### resultsDir\n\n```\nabstract var resultsDir: String?\n```\n\nName of the results directory. \n\n### unitTests\n\n```\nabstract val unitTests: UnitTestOptions\n```\n\nOptions for controlling unit tests execution."]]