UnitTestOptions

Options for controlling unit tests execution.

Properties

PropertyDescription
includeAndroidResources

Enables unit tests to use Android resources, assets, and manifests.

returnDefaultValues

Whether unmocked methods from android.jar should throw exceptions or return default values (i.e. zero or null).

Methods

MethodDescription
all(configClosure)

Configures all unit testing tasks.

Script blocks

No script blocks

Property details

boolean includeAndroidResources

Enables unit tests to use Android resources, assets, and manifests.

If you set this property to true, the plugin performs resource, asset, and manifest merging before running your unit tests. Your tests can then inspect a file called com/android/tools/test_config.properties on the classpath, which is a Java properties file with the following keys:

  • android_sdk_home: the absolute path to the Android SDK.
  • android_merged_resources: the absolute path to the merged resources directory, which contains all the resources from this subproject and all its dependencies.
  • android_merged_assets: the absolute path to the merged assets directory. For app subprojects, the merged assets directory contains assets from this subproject and its dependencies. For library subprojects, the merged assets directory contains only the assets from this subproject.
  • android_merged_manifest: the absolute path to the merged manifest file. Only app subprojects merge manifests of its dependencies. So, library subprojects won't include manifest components from their dependencies.
  • android_custom_package: the package name of the final R class. If you modify the application ID in your build scripts, this package name may not match the package attribute in the final app manifest.

boolean returnDefaultValues

Whether unmocked methods from android.jar should throw exceptions or return default values (i.e. zero or null).

See Test Your App for details.

Method details

void all(Closure<Test> configClosure)

Configures all unit testing tasks.

See Test for available options.

Inside the closure you can check the name of the task to configure only some test tasks, e.g.

android {
    testOptions {
        unitTests.all {
            if (it.name == 'testDebug') {
                systemProperty 'debug', 'true'
            }
        }
    }
}