TestOptions

Added in 4.2.0

interface TestOptions

Options for running tests.

Summary

Public functions

Unit
Unit
Unit

This function is deprecated. Renamed to emulatorSnapshots

Unit

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

Unit

Options for controlling unit tests execution.

Public properties

Boolean

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

NamedDomainObjectContainer<DeviceGroup>

This property is deprecated. deviceGroups is deprecated in testOptions, use managedDevices.groups instead

ExtensiblePolymorphicDomainObjectContainer<Device>

This property is deprecated. devices is deprecated in testOptions, use managedDevices.devices instead

EmulatorControl

Configures Android Emulator Grpc Access

EmulatorSnapshots

Configures Android Test Retention.

String

Specifies whether to use on-device test orchestration.

FailureRetention

This property is deprecated. Renamed to emulatorSnapshots

ManagedDevices

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

String?

Name of the reports directory.

String?

Name of the results directory.

Int?

Specifies value that overrides target sdk version number for tests in libraries.

String?

Specifies value that overrides target sdk preview number for tests in libraries.

UnitTestOptions

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(action: FailureRetention.() -> Unit): Unit

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 animationsDisabledBoolean

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

Added in 4.2.0
Deprecated in 7.3.0
val deviceGroupsNamedDomainObjectContainer<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.

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 devicesExtensiblePolymorphicDomainObjectContainer<Device>

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

These APIs are experimental and may change without notice.

devices is deprecated, use managedDevices.devices to specify Gradle Managed Devices

emulatorControl

Added in 8.1.0
val emulatorControlEmulatorControl

Configures Android Emulator Grpc Access

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

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 emulatorSnapshotsEmulatorSnapshots

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

Added in 4.2.0
var executionString

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

since 3.0.0

failureRetention

Added in 4.2.0
Deprecated in 7.0.0
val failureRetentionFailureRetention

managedDevices

Added in 7.2.0
val managedDevicesManagedDevices

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

reportDir

Added in 4.2.0
var reportDirString?

Name of the reports directory.

resultsDir

Added in 4.2.0
var resultsDirString?

Name of the results directory.

targetSdk

Added in 8.2.0
var targetSdkInt?

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
var targetSdkPreviewString?

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 unitTestsUnitTestOptions

Options for controlling unit tests execution.