HostTest

Added in 8.9.0-alpha06

@Incubating
interface HostTest : TestComponent


Model for Host Test components that contains build-time properties. Host Tests run on a JVM on your build machine, as opposed to DeviceTest which run on an Android Device.

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

The presence of this component in a variant is controlled by HostTestBuilder.enable which is accessible on subtypes of VariantBuilder that implement HasHostTestsBuilder

Summary

Public functions

Unit

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

Public properties

Boolean

Whether test coverage is enabled for this host test.

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.9.0-alpha06
@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 [HasHostTestsBuilder.hostTestsHasHostTestsBuilder.UNIT_TEST_TYPE?.enable] must be set to true (it is true by default).

Example :

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

to configure the Test task.

Public properties

codeCoverageEnabled

Added in 8.9.0-alpha06
val codeCoverageEnabledBoolean

Whether test coverage is enabled for this host test.

If enabled, this uses Jacoco to capture coverage and creates a report in the build directory.

You cannot change the value any longer, to change it, please use HostTestBuilder.enableCodeCoverage in the AndroidComponentsExtension.beforeVariants callback.