# HostTest

[View Source](https://cs.android.com/search?q=file:com/android/build/api/variant/HostTest.kt+class:com.android.build.api.variant.HostTest) Added in 8.5.0


```
interface HostTest : TestComponent
```

<br />

*** ** * ** ***

Model for Host Test components that contains build-time properties. Host Tests run on a JVM on your build machine, as opposed to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/DeviceTest` which run on an Android Device.

This object is accessible on subtypes of `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Variant` that implement `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HasHostTests`, via `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HasHostTests#hostTests()`. It is also part of `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Variant#nestedComponents()`.

The presence of this component in a variant is controlled by `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HostTestBuilder#enable()` which is accessible on subtypes of `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/VariantBuilder` that implement `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HasHostTestsBuilder`

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HostTest#configureTestTask(kotlin.Function1)(action: (https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` Runs some action to configure the Variant's unit test `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html` task. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `@https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HostTest#withTestTaskProvider(kotlin.Function1)(action: (https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskProvider.html<https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html>) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` Runs some action on the Variant's host test task's `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskProvider.html`. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HostTest#androidResourcesIncluded()` If this property is set to `true`, the plugin performs resource, asset, and manifest merging before running your host tests. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HostTest#codeCoverageEnabled()` Whether test coverage is enabled for this host test. |

### Inherited functions

From [com.android.build.api.variant.Component](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component) `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` `@https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html
https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#computeTaskName(kotlin.String,kotlin.String)(action: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, subject: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`

Utility method to create unique task name for component.
`https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` `@https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html
https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#configureJavaCompileTask(kotlin.Function1)(action: (https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/compile/JavaCompile.html) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`

Runs an action to configure Components's java compilation `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/compile/JavaCompile.html` task.
`https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` `@https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html
https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#getResolvableConfiguration(kotlin.String)(sourceSetConfigurationsAffix: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`

Access to the component's resolvable configuration corresponding to the source set configurations added via `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidComponentsExtension#addSourceSetConfigurations(kotlin.String)`.

### Inherited properties

From [com.android.build.api.variant.Component](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component) `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#annotationProcessorConfiguration()`

Access to the variant's annotation processor `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html`; for example, the debugAnnotationProcessor `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` for the debug variant.
`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifacts` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#artifacts()`

Access to the variant's buildable artifacts for build customization.
`https://docs.gradle.org/current/javadoc/org/gradle/api/file/FileCollection.html` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#compileClasspath()`

Access to the variant's compile classpath.
`https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#compileConfiguration()`

Access to the variant's compile `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html`; for example, the debugCompileClasspath `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` for the debug variant.
`https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#debuggable()`

Whether the produced artifacts will be debuggable
`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Instrumentation` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#instrumentation()`

Access to the variant's instrumentation options.
`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/JavaCompilation?` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#javaCompilation()`

Access to the variant's java compilation options.
`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/LifecycleTasks` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#lifecycleTasks()`

Provides access to the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/LifecycleTasks` created for this component.
`https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#namespace()`

The namespace of the generated R and BuildConfig classes.
`https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#runtimeConfiguration()`

Access to the variant's runtime `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html`; for example, the debugRuntimeClasspath `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` for the debug variant.
`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Sources` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#sources()`

Access to variant's source files.
From [com.android.build.api.variant.ComponentIdentity](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ComponentIdentity) `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html?` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ComponentIdentity#buildType()`

Build type name.
`https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html?` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ComponentIdentity#flavorName()`

The multi-flavor name of the variant.
`https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ComponentIdentity#name()`

Component's name.
`https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-pair/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>>` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ComponentIdentity#productFlavors()`

List of flavor names.
From [com.android.build.api.variant.TestComponent](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestComponent) `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/MapProperty.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestComponent#manifestPlaceholders()`

`https://docs.gradle.org/current/javadoc/org/gradle/api/provider/MapProperty.html` 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 `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html` 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: (https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | to configure the `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html` task. |

### withTestTaskProvider

Added in 9.6.0-alpha03

```
@Incubating
fun withTestTaskProvider(action: (TaskProvider<Test>) -> Unit): Unit
```

Runs some action on the Variant's host test task's `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskProvider.html`.

The action will only run if the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HostTest` is enabled. In particular the \[HasHostTestsBuilder.hostTestsHasHostTestsBuilder.UNIT_TEST_TYPE?.enable\] must be set to true (it is true by default).

This is particularly useful to set manual tasks dependencies. However, you should avoid calling `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskProvider.html#get--` as it will automatically configure the task even if it is not scheduled to run, instead use `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HostTest#configureTestTask(kotlin.Function1)`

Example :

```
androidComponents {
    onVariants { variant ->
        variant.hostTests[HostTestsBuilder.UNIT_TEST_TYPE]?.withTestTaskProvider { testTaskProvider ->
            someAnchorTask.dependsOn(testTaskProvider)
        }
    }
}
```

| Parameters |
|---|---|
| `action: (https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskProvider.html<https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html>) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | on the test task `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskProvider.html`. |

## Public properties

### androidResourcesIncluded

Added in 9.6.0-alpha03

```
val androidResourcesIncluded: Boolean
```

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 codeCoverageEnabled: Boolean
```

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 `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HostTestBuilder#enableCodeCoverage()` in the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidComponentsExtension#beforeVariants(com.android.build.api.variant.VariantSelector,kotlin.Function1)` callback.