TestOptions

public interface TestOptions


Options for running tests.

Summary

Public methods

abstract void
abstract void
abstract void

This method is deprecated. Renamed to emulatorSnapshots

abstract boolean

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

abstract @NonNull NamedDomainObjectContainer<@NonNull DeviceGroup>

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

abstract @NonNull ExtensiblePolymorphicDomainObjectContainer<@NonNull Device>

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

abstract @NonNull EmulatorControl

Configures Android Emulator Grpc Access

abstract @NonNull EmulatorSnapshots

Configures Android Test Retention.

abstract @NonNull String

Specifies whether to use on-device test orchestration.

abstract @NonNull FailureRetention
abstract @NonNull ManagedDevices

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

abstract String

Name of the reports directory.

abstract String

Name of the results directory.

abstract Integer

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

abstract String

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

abstract @NonNull UnitTestOptions

Options for controlling unit tests execution.

abstract void

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

abstract void
setAnimationsDisabled(boolean animationsDisabled)

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

abstract void

Specifies whether to use on-device test orchestration.

abstract void
setReportDir(String reportDir)

Name of the reports directory.

abstract void
setResultsDir(String resultsDir)

Name of the results directory.

abstract void
setTargetSdk(Integer targetSdk)

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

abstract void
setTargetSdkPreview(String targetSdkPreview)

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

abstract void

Options for controlling unit tests execution.

Public methods

emulatorControl

@Incubating
abstract void emulatorControl(
    @ExtensionFunctionType @NonNull Function1<@NonNull EmulatorControlUnit> action
)

emulatorSnapshots

@Incubating
abstract void emulatorSnapshots(
    @ExtensionFunctionType @NonNull Function1<@NonNull EmulatorSnapshotsUnit> action
)

failureRetention

@Incubating
abstract void failureRetention(
    @ExtensionFunctionType @NonNull Function1<@NonNull FailureRetentionUnit> action
)

getAnimationsDisabled

abstract boolean getAnimationsDisabled()

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.

getDeviceGroups

@Incubating
abstract @NonNull NamedDomainObjectContainer<@NonNull DeviceGroupgetDeviceGroups()

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.

getDevices

@Incubating
abstract @NonNull ExtensiblePolymorphicDomainObjectContainer<@NonNull DevicegetDevices()

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

getEmulatorControl

@Incubating
abstract @NonNull EmulatorControl getEmulatorControl()

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")
}
}

getEmulatorSnapshots

@Incubating
abstract @NonNull EmulatorSnapshots getEmulatorSnapshots()

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

getExecution

abstract @NonNull String getExecution()

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

getFailureRetention

@Incubating
abstract @NonNull FailureRetention getFailureRetention()

getManagedDevices

@Incubating
abstract @NonNull ManagedDevices getManagedDevices()

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

getReportDir

abstract String getReportDir()

Name of the reports directory.

getResultsDir

abstract String getResultsDir()

Name of the results directory.

getTargetSdk

abstract Integer getTargetSdk()

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.

getTargetSdkPreview

abstract String getTargetSdkPreview()

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.

getUnitTests

abstract @NonNull UnitTestOptions getUnitTests()

Options for controlling unit tests execution.

managedDevices

@Incubating
abstract void managedDevices(
    @ExtensionFunctionType @NonNull Function1<@NonNull ManagedDevicesUnit> action
)

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

setAnimationsDisabled

abstract void setAnimationsDisabled(boolean animationsDisabled)

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.

setExecution

abstract void setExecution(@NonNull String execution)

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

setReportDir

abstract void setReportDir(String reportDir)

Name of the reports directory.

setResultsDir

abstract void setResultsDir(String resultsDir)

Name of the results directory.

setTargetSdk

abstract void setTargetSdk(Integer targetSdk)

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.

setTargetSdkPreview

abstract void setTargetSdkPreview(String targetSdkPreview)

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

abstract void unitTests(
    @ExtensionFunctionType @NonNull Function1<@NonNull UnitTestOptionsUnit> action
)

Options for controlling unit tests execution.