Stay organized with collections
Save and categorize content based on your preferences.
TestedExtension
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 functions |
@Incubating Unit |
Options to configure the test fixtures.
|
Public properties |
String |
Specifies the build type that the plugin should use to test the module.
|
TestFixtures |
Options to configure the test fixtures.
|
String? |
The namespace used by the android test and unit test components for the generated R and BuildConfig classes.
|
Public functions
Public properties
testBuildType
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".
testNamespace
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# TestedExtension\n===============\n\n\n```\ninterface TestedExtension\n```\n\n\u003cbr /\u003e\n\nKnown direct subclasses \n[ApplicationExtension](/reference/tools/gradle-api/8.0/com/android/build/api/dsl/ApplicationExtension), [DynamicFeatureExtension](/reference/tools/gradle-api/8.0/com/android/build/api/dsl/DynamicFeatureExtension), [LibraryExtension](/reference/tools/gradle-api/8.0/com/android/build/api/dsl/LibraryExtension) \n\n|--------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------|\n| [ApplicationExtension](/reference/tools/gradle-api/8.0/com/android/build/api/dsl/ApplicationExtension) | Extension for the Android Gradle Plugin Application plugin. |\n| [DynamicFeatureExtension](/reference/tools/gradle-api/8.0/com/android/build/api/dsl/DynamicFeatureExtension) | Extension for the Android Dynamic Feature Gradle Plugin. |\n| [LibraryExtension](/reference/tools/gradle-api/8.0/com/android/build/api/dsl/LibraryExtension) | Extension for the Android Library Gradle Plugin. |\n\n*** ** * ** ***\n\nCommon extension properties for the Android Application. Library and Dynamic Feature Plugins that relate to testing\n\nOnly the Android Gradle Plugin should create instances of this interface.\n\nSummary\n-------\n\n| ### Public functions ||\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `@`[Incubating](https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html)` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [testFixtures](/reference/tools/gradle-api/8.0/com/android/build/api/dsl/TestedExtension#testFixtures(kotlin.Function1))`(action: @`[ExtensionFunctionType](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html)` `[TestFixtures](/reference/tools/gradle-api/8.0/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| ### Public properties ||\n|----------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | [testBuildType](/reference/tools/gradle-api/8.0/com/android/build/api/dsl/TestedExtension#testBuildType()) 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| [TestFixtures](/reference/tools/gradle-api/8.0/com/android/build/api/dsl/TestFixtures) | [testFixtures](/reference/tools/gradle-api/8.0/com/android/build/api/dsl/TestedExtension#testFixtures()) Options to configure the test fixtures. |\n| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` | [testNamespace](/reference/tools/gradle-api/8.0/com/android/build/api/dsl/TestedExtension#testNamespace()) The namespace used by the android test and unit test components for the generated R and BuildConfig classes. |\n\nPublic functions\n----------------\n\n### testFixtures\n\n```\n@Incubating\nfun testFixtures(action: @ExtensionFunctionType TestFixtures.() -\u003e Unit): Unit\n```\n\nOptions to configure the test fixtures.\n\nPublic properties\n-----------------\n\n### testBuildType\n\n```\nvar testBuildType: String\n```\n\nSpecifies the [build type](https://developer.android.com/studio/build/build-variants.html#build-types) that the plugin should use to test the module.\n\nBy 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.\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 [product flavors](https://developer.android.com/studio/build/build-variants.html#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:\n\n- `connectedFreeDebugAndroidTest`: builds and deploys a `freeDebug` test APK and module APK, and runs instrumented tests for that variant.\n\n- `connectedPaidDebugAndroidTest`: builds and deploys a `paidDebug` test APK and module APK, and runs instrumented tests for that variant.\n\nTo learn more, read [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 only for build variants that use the test build type. So, by default, running `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```\nval testFixtures: TestFixtures\n```\n\nOptions to configure the test fixtures. \n\n### testNamespace\n\n```\nvar testNamespace: String?\n```\n\nThe namespace used by the android test and unit test components for the generated R and BuildConfig classes."]]