# DeviceTest

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


```
interface DeviceTest : GeneratesTestApk, HasAndroidResources, TestComponent
```

<br />

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

|---|---|
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidTest` | Model for Android Test components that contains build-time properties |

*** ** * ** ***

Model for Device 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/HasDeviceTests`, via `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HasDeviceTests#deviceTests()`. 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/HasDeviceTestsBuilder#deviceTests()` and `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/DeviceTestBuilder#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/HasDeviceTestsBuilder`

## 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/DeviceTest#configureTestTask(kotlin.Function1)(action: (https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` Runs some action to configure the Variant's device test 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/DeviceTest#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/Task.html>) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` Runs some action on the Variant's device test task's `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskProvider.html`. |

| ### Public properties |
|---|---|
| `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.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/DeviceTest#applicationId()` Variant's application ID as present in the final manifest file of the APK. |
| `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/MapProperty.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/BuildConfigField<https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/Serializable.html>>?` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/DeviceTest#buildConfigFields()` Variant's `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/BuildConfigField` which will be generated in the BuildConfig class. |
| `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/DeviceTest#codeCoverageEnabled()` Whether test coverage is enabled for this device test. |
| `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/ListProperty.html<https://docs.gradle.org/current/javadoc/org/gradle/api/file/RegularFile.html>` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/DeviceTest#proguardFiles()` List of proguard configuration files for this variant. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/SigningConfig?` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/DeviceTest#signingConfig()` Variant's signingConfig, initialized by the corresponding DSL element. |

### 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)`.
From [com.android.build.api.variant.HasAndroidResources](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HasAndroidResources) `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ResValue.Key` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HasAndroidResources#makeResValueKey(kotlin.String,kotlin.String)(type: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, name: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`

Make a `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ResValue.Key` to interact with `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HasAndroidResources#resValues()`'s `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/MapProperty.html`

### 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.GeneratesApk](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/GeneratesApk) `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidResources` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/GeneratesApk#androidResources()`

Variant's android resources processing configuration, initialized by the corresponding global DSL element.
`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Dexing` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/GeneratesApk#dexing()`

Variant's specific dexing options
`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidVersion` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/GeneratesApk#minSdk()`

Min SDK version for this variant
`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ApkOutputProviders` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/GeneratesApk#outputProviders()`

Provides access to built artifacts output(e.g. APK) produced by this Variant.
`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ApkPackaging` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/GeneratesApk#packaging()`

Variant's packagingOptions, initialized by the corresponding global DSL element.
`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Renderscript?` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/GeneratesApk#renderscript()`

Variant specific settings for the renderscript compiler.
`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidVersion` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/GeneratesApk#targetSdk()`

Target SDK version for this variant.
From [com.android.build.api.variant.GeneratesTestApk](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/GeneratesTestApk) `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.html<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/GeneratesTestApk#functionalTest()`

The functionalTest value to use to run the tests.
`https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.html<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/GeneratesTestApk#handleProfiling()`

The handleProfiling value to use to run the tests.
`https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.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/GeneratesTestApk#instrumentationRunner()`

The instrumentationRunner to use to run the tests.
`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/GeneratesTestApk#instrumentationRunnerArguments()`

The instrumentationRunnerArguments to use to run the tests.
`https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.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/GeneratesTestApk#testLabel()`

The test label, or "" if none defined.
From [com.android.build.api.variant.HasAndroidResources](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HasAndroidResources) `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.html<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/HasAndroidResources#pseudoLocalesEnabled()`

Variant's is pseudo locales enabled, initialized by the corresponding DSL elements.
`https://docs.gradle.org/current/javadoc/org/gradle/api/provider/MapProperty.html<https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ResValue.Key, https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ResValue>` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HasAndroidResources#resValues()`

Variant's `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ResValue` which will be generated.
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 9.6.0-alpha03

```
@Incubating
fun configureTestTask(action: (Task) -> Unit): Unit
```

Runs some action to configure the Variant's device test 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/HasDeviceTestsBuilder#deviceTests()`.\\\[`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/DeviceTestBuilder#ANDROID_TEST_TYPE()`\\\]?.enable\] must be set to true (it is true by default).

Example :

```
androidComponents {
    onVariants { variant ->
        variant.deviceTests[DeviceTestBuilder.ANDROID_TEST_TYPE]?.configureTestTask { testTask ->
            testTask.beforeTest { descriptor ->
                println("Running test: " + descriptor)
            }
        }
    }
}
```

| Parameters |
|---|---|
| `action: (https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | to configure the test task. At this point, you should not assume the passed test Task is of `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html` type although this may change in the future. |

### withTestTaskProvider

Added in 9.6.0-alpha03

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

Runs some action on the Variant's device 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/DeviceTest` is enabled. In particular the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HasDeviceTestsBuilder#deviceTests()`.\\\[`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/DeviceTestBuilder#ANDROID_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/DeviceTest#configureTestTask(kotlin.Function1)`

Example :

```
androidComponents {
    onVariants { variant ->
        variant.deviceTests[DeviceTestBuilder.ANDROID_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/Task.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

### applicationId

```
val applicationId: Property<String>
```

Variant's application ID as present in the final manifest file of the APK.

### buildConfigFields

Added in 8.4.0

```
val buildConfigFields: MapProperty<String, BuildConfigField<Serializable>>?
```

Variant's `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/BuildConfigField` which will be generated in the BuildConfig class.

### codeCoverageEnabled

Added in 8.5.0

```
val codeCoverageEnabled: Boolean
```

Whether test coverage is enabled for this device 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/DeviceTestBuilder#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.

### proguardFiles

Added in 8.4.0

```
val proguardFiles: ListProperty<RegularFile>
```

List of proguard configuration files for this variant. The list is initialized from the corresponding DSL element, and cannot be queried at configuration time. At configuration time, you can only add new elements to the list.

### signingConfig

Added in 8.4.0

```
val signingConfig: SigningConfig?
```

Variant's signingConfig, initialized by the corresponding DSL element.

| Returns |
|---|---|
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/SigningConfig?` | Variant's config or null if the variant is not configured for signing. |