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 |
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
.
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.
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'
}
}
failureRetention
abstract var failureRetention: FailureRetention
Configures Android Test Retention.
Android Test Retention automatically takes emulator snapshots on test failures. It can only
work with Unified Test Platform (UTP), thus would require
"execution 'ANDROID_TEST_ORCHESTRATOR'".
android {
testOptions {
execution 'ANDROID_TEST_ORCHESTRATOR'
failureRetention {
enable true
maxSnapshots 5
compressSnapshots false
}
}
}
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.
[[["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,["# 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) | [unitTests](#unitTests(kotlin.Function1))`(`action:` `[UnitTestOptions](/reference/tools/gradle-api/4.2/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/4.2/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/4.2/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 [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/4.2/com/android/build/api/dsl/FailureRetention) | [failureRetention](#failureRetention:com.android.build.api.dsl.FailureRetention) Configures Android Test Retention. |\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/4.2/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### 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\nTo learn more about running 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### 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 var failureRetention: FailureRetention\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), thus would require\n\"execution 'ANDROID_TEST_ORCHESTRATOR'\". \n\n```scdoc\nandroid {\n testOptions {\n execution 'ANDROID_TEST_ORCHESTRATOR'\n failureRetention {\n enable true\n maxSnapshots 5\n compressSnapshots false\n }\n }\n}\n``` \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."]]