Stay organized with collections
Save and categorize content based on your preferences.
TestedExtension
@Incubating interface TestedExtension
Common extension properties for the Android Application. Library and Dynamic Feature Plugins that
relate to testing
Only the Android Gradle Plugin should create instances of this interface.
Summary
Public methods
|
abstract Unit |
Options to configure the test fixtures.
|
Properties
|
abstract String |
Specifies the
build type
that the plugin should use to test the module.
|
abstract TestFixtures |
Options to configure the test fixtures.
|
abstract String? |
The namespace used by the android test and unit test components for the generated R and
BuildConfig classes.
|
Public methods
testFixtures
abstract fun testFixtures(action: TestFixtures.() -> Unit): Unit
Options to configure the test fixtures.
Properties
testBuildType
abstract var testBuildType: String
Specifies the
build type
that the plugin should use to test the module.
By default, the Android plugin uses the "debug" build type. This means that when you
deploy your instrumented tests using gradlew connectedAndroidTest
, it uses the
code and resources from the module's "debug" build type to create the test APK. The plugin
then deploys the "debug" version of both the module's APK and the test APK to a connected
device, and runs your tests.
To change the test build type to something other than "debug", specify it as follows:
android {
// Changes the test build type for instrumented tests to "stage".
testBuildType "stage"
}
If your module configures
product flavors
the plugin creates a test APK and deploys tests for each build variant that uses
the test build type. For example, consider if your module configures "debug" and "release"
build types, and "free" and "paid" product flavors. By default, when you run your
instrumented tests using gradlew connectedAndroidTest
, the plugin performs
executes the following tasks:
connectedFreeDebugAndroidTest
: builds and deploys a freeDebug
test APK and module APK, and runs instrumented tests for that variant.
connectedPaidDebugAndroidTest
: builds and deploys a paidDebug
test APK and module APK, and runs instrumented tests for that variant.
To learn more, read
Create instrumented test for a build variant
Note: You can execute connected<BuildVariant>AndroidTest
tasks
only for build variants that use the test build type. So, by default, running
connectedStageAndroidTest
results in the following build error:
Task 'connectedStageAndroidTest' not found in root project
You can resolve this issue by changing the test build type to "stage".
testFixtures
abstract val testFixtures: TestFixtures
Options to configure the test fixtures.
testNamespace
abstract var testNamespace: String?
The namespace used by the android test and unit test components for the generated R and
BuildConfig classes.
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.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# TestedExtension\n===============\n\n```\n@Incubating interface TestedExtension\n```\n\n|------------------------------------------------|\n| [com.android.build.api.dsl.TestedExtension](#) |\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Direct Subclasses [ApplicationExtension](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/ApplicationExtension), [DynamicFeatureExtension](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/DynamicFeatureExtension), [LibraryExtension](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/LibraryExtension) |--------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------| | [ApplicationExtension](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/ApplicationExtension) | Extension for the Android Gradle Plugin Application plugin. | | [DynamicFeatureExtension](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/DynamicFeatureExtension) | Extension for the Android Dynamic Feature Gradle Plugin. | | [LibraryExtension](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/LibraryExtension) | Extension for the Android Library Gradle Plugin. | |\n\nCommon extension properties for the Android Application. Library and Dynamic Feature Plugins that\nrelate to testing\n\nOnly the Android Gradle Plugin should create instances of this interface.\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [testFixtures](#testFixtures(kotlin.Function1))`(`action:` `[TestFixtures](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/TestFixtures).()` `-\u003e` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` Options to configure the test fixtures. |\n\n| ### Properties ||\n|-------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | [testBuildType](#testBuildType:kotlin.String) Specifies the [build type](https://developer.android.com/studio/build/build-variants.html#build-types) that the plugin should use to test the module. |\n| abstract [TestFixtures](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/TestFixtures) | [testFixtures](#testFixtures:com.android.build.api.dsl.TestFixtures) Options to configure the test fixtures. |\n| abstract [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)? | [testNamespace](#testNamespace:kotlin.String) The namespace used by the android test and unit test components for the generated R and BuildConfig classes. |\n\nPublic methods\n--------------\n\n### testFixtures\n\n```\nabstract fun testFixtures(action: TestFixtures.() -\u003e Unit): Unit\n```\n\nOptions to configure the test fixtures.\n\nProperties\n----------\n\n### testBuildType\n\n```\nabstract var testBuildType: String\n```\n\nSpecifies the\n[build type](https://developer.android.com/studio/build/build-variants.html#build-types)\nthat the plugin should use to test the module.\n\nBy default, the Android plugin uses the \"debug\" build type. This means that when you\ndeploy your instrumented tests using `gradlew connectedAndroidTest`, it uses the\ncode and resources from the module's \"debug\" build type to create the test APK. The plugin\nthen deploys the \"debug\" version of both the module's APK and the test APK to a connected\ndevice, and runs your tests.\n\nTo change the test build type to something other than \"debug\", specify it as follows: \n\n```carbon\nandroid {\n // Changes the test build type for instrumented tests to \"stage\".\n testBuildType \"stage\"\n}\n```\n\nIf your module configures\n[product flavors](https://developer.android.com/studio/build/build-variants.html#product-flavors)\nthe plugin creates a test APK and deploys tests for each build variant that uses\nthe test build type. For example, consider if your module configures \"debug\" and \"release\"\nbuild types, and \"free\" and \"paid\" product flavors. By default, when you run your\ninstrumented tests using `gradlew connectedAndroidTest`, the plugin performs\nexecutes the following tasks:\n\n- `connectedFreeDebugAndroidTest`: builds and deploys a `freeDebug` test APK and module APK, and runs instrumented tests for that variant.\n- `connectedPaidDebugAndroidTest`: builds and deploys a `paidDebug` test APK and module APK, and runs instrumented tests for that variant.\n\nTo learn more, read\n[Create instrumented test for a build variant](https://developer.android.com/studio/test/index.html#create_instrumented_test_for_a_build_variant)\n\n**Note:** You can execute `connected\u003cBuildVariant\u003eAndroidTest` tasks\nonly for build variants that use the test build type. So, by default, running\n`connectedStageAndroidTest` results in the following build error: \n\n```text\nTask 'connectedStageAndroidTest' not found in root project\n```\n\nYou can resolve this issue by changing the test build type to \"stage\". \n\n### testFixtures\n\n```\nabstract val testFixtures: TestFixtures\n```\n\nOptions to configure the test fixtures. \n\n### testNamespace\n\n```\nabstract var testNamespace: String?\n```\n\nThe namespace used by the android test and unit test components for the generated R and\nBuildConfig classes."]]