# UnitTest

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


```
interface UnitTest : TestComponent
```

<br />

Known direct subclasses [UnitTest](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/component/UnitTest)

|---|---|
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/component/UnitTest` | **This interface is deprecated.** Use the com.android.build.api.variant package |

*** ** * ** ***

`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component` for unit tests

Model for Unit Test components that contains build-time properties

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/HasUnitTest`, via `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HasUnitTest#unitTest()`. It is also part of `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Variant#nestedComponents()`.

Prefer using `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HostTest` rather than this interface which will be deprecated once `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HostTest` is stable.

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/HasUnitTestBuilder#enableUnitTest()` 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/HasUnitTestBuilder`

## Summary

| ### Public functions |
|---|---|
| `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/UnitTest#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. |

### 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.4.0

```
@Incubating
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 `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/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: (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. |