HostTest

Added in 8.5.0

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
configureTestTask(action: (Test) -> Unit)

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

Public properties

Boolean

If this property is set to true, the plugin performs resource, asset, and manifest merging before running your host tests.

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

Runs an action to configure Components's java compilation JavaCompile task.

Configuration
@Incubating
getResolvableConfiguration(sourceSetConfigurationsAffix: String)

Access to the component's resolvable configuration corresponding to the source set configurations added via AndroidComponentsExtension.addSourceSetConfigurations.

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.0
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

androidResourcesIncluded

Added in 9.0.0-alpha13
val androidResourcesIncludedBoolean

If this property is set to true, the plugin performs resource, asset, and manifest merging before running your host tests. Your tests can then inspect a file called com/android/tools/test_config.properties on the classpath, which is a Java properties file with the following keys:

android_resource_apk: the path to the APK-like zip file containing merged resources, which includes all the resources from the current subproject and all its dependencies.

android_merged_assets: the path to the directory containing merged assets. The merged assets directory contains assets from the current subproject and it dependencies.

android_merged_manifest: the path to the merged manifest file. Only app subprojects have the manifest merged from their dependencies. Library subprojects do not include manifest components from their dependencies.

android_custom_package: the package name (namespace) of the final R class.

Note that the paths above are relative paths (relative to the current project directory, not the root project directory).

codeCoverageEnabled

Added in 8.5.0
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.