UnitTest

Added in 7.0.0

interface UnitTest : TestComponent

Known direct subclasses
UnitTest

This interface is deprecated. Use the com.android.build.api.variant package


Component for unit tests

Model for Unit Test components that contains build-time properties

This object is accessible on subtypes of Variant that implement HasUnitTest, via HasUnitTest.unitTest. It is also part of Variant.nestedComponents.

Prefer using HostTest rather than this interface which will be deprecated once HostTest is stable.

The presence of this component in a variant is controlled by HasUnitTestBuilder.enableUnitTest which is accessible on subtypes of VariantBuilder that implement HasUnitTestBuilder

Summary

Public functions

Unit

Runs some action to configure the Variant's unit test Test task.

Inherited functions

From com.android.build.api.variant.Component
String
@Incubating
computeTaskName(action: String, subject: String)

Utility method to create unique task name for component.

Unit

This function is deprecated. Will be removed in v9.0, use the instrumentation block.

Unit
<ParamT : InstrumentationParameters> transformClassesWith(
    classVisitorFactoryImplClass: Class<AsmClassVisitorFactory<ParamT>>,
    scope: InstrumentationScope,
    instrumentationParamsConfig: (ParamT) -> Unit
)

This function is deprecated. Will be removed in v9.0, use the instrumentation block.

Inherited properties

From com.android.build.api.variant.Component
Configuration

Access to the variant's annotation processor Configuration; for example, the debugAnnotationProcessor Configuration for the debug variant.

Artifacts

Access to the variant's buildable artifacts for build customization.

FileCollection

Access to the variant's compile classpath.

Configuration

Access to the variant's compile Configuration; for example, the debugCompileClasspath Configuration for the debug variant.

Boolean

Whether the produced artifacts will be debuggable

Instrumentation

Access to the variant's instrumentation options.

JavaCompilation

Access to the variant's java compilation options.

LifecycleTasks

Provides access to the LifecycleTasks created for this component.

Provider<String>

The namespace of the generated R and BuildConfig classes.

Configuration

Access to the variant's runtime Configuration; for example, the debugRuntimeClasspath Configuration for the debug variant.

Sources

Access to variant's source files.

From com.android.build.api.variant.ComponentIdentity
String?

Build type name.

String?

The multi-flavor name of the variant.

String

Component's name.

List<Pair<StringString>>

List of flavor names.

From com.android.build.api.variant.TestComponent
MapProperty<StringString>

MapProperty of the test component's manifest placeholders.

Public functions

configureTestTask

Added in 8.5.2
@Incubating
fun configureTestTask(action: (Test) -> Unit): Unit

Runs some action to configure the Variant's unit test Test task.

The action will only run if the task is configured. In particular the HasUnitTestBuilder.enableUnitTest] must be set to true (it is true by default).

Example :

androidComponents {
onVariants { variant ->
variant.unitTest?.configureTestTask { testTask ->
testTask.beforeTest { descriptor ->
println("Running test: " + descriptor)
}
}
}
}
Parameters
action: (Test) -> Unit

to configure the Test task.