TestOptions

@Incubating interface TestOptions
com.android.build.api.dsl.TestOptions

Options for running tests.

Summary

Public methods

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

Options for controlling unit tests execution.

Properties

abstract Boolean

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

abstract NamedDomainObjectContainer<DeviceGroup>

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

abstract ExtensiblePolymorphicDomainObjectContainer<Device>

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

abstract String

Specifies whether to use on-device test orchestration.

abstract FailureRetention

Configures Android Test Retention.

abstract String?

Name of the reports directory.

abstract String?

Name of the results directory.

abstract UnitTestOptions

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.

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.

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.