public abstract class TestedExtension extends BaseExtension implements com.android.build.gradle.TestedAndroidConfig
AppExtension
, LibraryExtension
, and
FeatureExtension
.
To learn more about testing Android projects, read Test Your App.
logger, project
Constructor and Description |
---|
TestedExtension(org.gradle.api.Project project,
com.android.build.gradle.options.ProjectOptions projectOptions,
org.gradle.internal.reflect.Instantiator instantiator,
com.android.builder.core.AndroidBuilder androidBuilder,
com.android.build.gradle.internal.SdkHandler sdkHandler,
org.gradle.api.NamedDomainObjectContainer<com.android.build.gradle.internal.dsl.BuildType> buildTypes,
org.gradle.api.NamedDomainObjectContainer<com.android.build.gradle.internal.dsl.ProductFlavor> productFlavors,
org.gradle.api.NamedDomainObjectContainer<com.android.build.gradle.internal.dsl.SigningConfig> signingConfigs,
org.gradle.api.NamedDomainObjectContainer<com.android.build.gradle.api.BaseVariantOutput> buildOutputs,
com.android.build.gradle.internal.ExtraModelInfo extraModelInfo,
boolean isDependency) |
Modifier and Type | Method and Description |
---|---|
void |
addTestVariant(com.android.build.gradle.api.TestVariant testVariant) |
void |
addUnitTestVariant(com.android.build.gradle.api.UnitTestVariant testVariant) |
java.lang.String |
getTestBuildType()
Specifies the build
type that the plugin should use to test the module.
|
org.gradle.api.DomainObjectSet<com.android.build.gradle.api.TestVariant> |
getTestVariants()
Returns a collection of Android test build variants.
|
org.gradle.api.DomainObjectSet<com.android.build.gradle.api.UnitTestVariant> |
getUnitTestVariants()
Returns a collection of Android unit test build variants.
|
void |
setTestBuildType(java.lang.String testBuildType) |
aaptOptions, adbOptions, addVariant, buildToolsVersion, buildTypes, checkWritability, compileOptions, compileSdkVersion, compileSdkVersion, dataBinding, defaultConfig, defaultPublishConfig, deviceProvider, dexOptions, disableWrite, externalNativeBuild, flavorDimensions, generatePureSplits, getAaptOptions, getAdbExe, getAdbExecutable, getAdbOptions, getAidlPackageWhiteList, getBaseFeature, getBootClasspath, getBuildOutputs, getBuildToolsRevision, getBuildToolsVersion, getBuildTypes, getCompileOptions, getCompileSdkVersion, getDataBinding, getDefaultConfig, getDefaultProguardFile, getDefaultPublishConfig, getDeviceProviders, getDexOptions, getExternalNativeBuild, getFlavorDimensionList, getGeneratePureSplits, getJacoco, getLibraryRequests, getLintOptions, getNdkDirectory, getPackageBuildConfig, getPackagingOptions, getProductFlavors, getResourcePrefix, getSdkDirectory, getSigningConfigs, getSourceSets, getSplits, getTestOptions, getTestServers, getTransforms, getTransformsDependencies, getVariantFilter, jacoco, lintOptions, packagingOptions, productFlavors, registerArtifactType, registerBuildTypeSourceProvider, registerJavaArtifact, registerMultiFlavorSourceProvider, registerProductFlavorSourceProvider, registerTransform, resourcePrefix, setBuildToolsVersion, setCompileSdkVersion, setCompileSdkVersion, setDefaultPublishConfig, setGeneratePureSplits, setPublishNonDefault, setVariantFilter, signingConfigs, sourceSets, splits, testOptions, testServer, useLibrary, useLibrary, variantFilter, wrapJavaSourceSet
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAaptOptions, getAdbOptions, getAidlPackageWhiteList, getBaseFeature, getBuildOutputs, getBuildToolsRevision, getBuildToolsVersion, getBuildTypes, getCompileOptions, getCompileSdkVersion, getDataBinding, getDefaultConfig, getDefaultPublishConfig, getDeviceProviders, getDexOptions, getExternalNativeBuild, getFlavorDimensionList, getGeneratePureSplits, getJacoco, getLibraryRequests, getLintOptions, getPackageBuildConfig, getPackagingOptions, getProductFlavors, getResourcePrefix, getSigningConfigs, getSourceSets, getSplits, getTestOptions, getTestServers, getTransforms, getTransformsDependencies, getVariantFilter
public TestedExtension(@NonNull org.gradle.api.Project project, @NonNull com.android.build.gradle.options.ProjectOptions projectOptions, @NonNull org.gradle.internal.reflect.Instantiator instantiator, @NonNull com.android.builder.core.AndroidBuilder androidBuilder, @NonNull com.android.build.gradle.internal.SdkHandler sdkHandler, @NonNull org.gradle.api.NamedDomainObjectContainer<com.android.build.gradle.internal.dsl.BuildType> buildTypes, @NonNull org.gradle.api.NamedDomainObjectContainer<com.android.build.gradle.internal.dsl.ProductFlavor> productFlavors, @NonNull org.gradle.api.NamedDomainObjectContainer<com.android.build.gradle.internal.dsl.SigningConfig> signingConfigs, @NonNull org.gradle.api.NamedDomainObjectContainer<com.android.build.gradle.api.BaseVariantOutput> buildOutputs, @NonNull com.android.build.gradle.internal.ExtraModelInfo extraModelInfo, boolean isDependency)
@NonNull public org.gradle.api.DomainObjectSet<com.android.build.gradle.api.TestVariant> getTestVariants()
To process elements in this collection, you should use the
all
iterator. That's because the plugin populates this collection only after
the project is evaluated. Unlike the each
iterator, using all
processes future elements as the plugin creates them.
To learn more about testing Android projects, read Test Your App.
getTestVariants
in interface com.android.build.gradle.TestedAndroidConfig
public void addTestVariant(com.android.build.gradle.api.TestVariant testVariant)
@NonNull public org.gradle.api.DomainObjectSet<com.android.build.gradle.api.UnitTestVariant> getUnitTestVariants()
To process elements in this collection, you should use the
all
iterator. That's because the plugin populates this collection only after
the project is evaluated. Unlike the each
iterator, using all
processes future elements as the plugin creates them.
To learn more about testing Android projects, read Test Your App.
getUnitTestVariants
in interface com.android.build.gradle.TestedAndroidConfig
public void addUnitTestVariant(com.android.build.gradle.api.UnitTestVariant testVariant)
@NonNull public java.lang.String getTestBuildType()
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".
getTestBuildType
in interface com.android.build.gradle.AndroidConfig
getTestBuildType
in interface com.android.build.gradle.TestedAndroidConfig
public void setTestBuildType(java.lang.String testBuildType)