# TestSuite

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


```
interface TestSuite : Named
```

<br />

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

|---|---|
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ScreenshotTestSuite` | Model for screenshot test suites in the Variant API. |

*** ** * ** ***

Model for test suites.

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/HasTestSuites`, via `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HasTestSuites#suites()`.

## 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/TestSuite#configureTestTasks(kotlin.Function2)(action: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html.(context: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/TestTaskContext) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` Configures the test tasks for this test target. |
| `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.html<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/TestSuite#instrumentationRunner(com.android.build.api.variant.TestSuiteSourceSet.TestApk)(source: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuiteSourceSet.TestApk)` The instrumentationRunner to use to run the tests. |
| `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/TestSuite#withTestTaskProviders(kotlin.Function2)(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>.(context: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/TestTaskContext) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` Runs some action on the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuite` 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/TestSuite#codeCoverageEnabled()` Whether test coverage is enabled for this test suite. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/JUnitEngineSpec` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuite#junitEngineSpec()` Return the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/JUnitEngineSpec` for this test suite. |
| `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.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/TestSuite#requiresUpdateTask()` Whether this test suite requires an extra update task. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/index.html<https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuiteSourceSet>` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuite#sources()` Return the list of sourcesets associated with this test suite. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/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/TestSuiteTarget>` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuite#targets()` Return the list of `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuiteTarget` for this test suite in this variant. |

### Inherited properties

From [org.gradle.api.Named](https://docs.gradle.org/current/javadoc/org/gradle/api/Named.html) `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` `https://docs.gradle.org/current/javadoc/org/gradle/api/Named.html#name`

## Public functions

### configureTestTasks

Added in 9.6.0-alpha03

```
fun configureTestTasks(action: Test.(context: TestTaskContext) -> Unit): Unit
```

Configures the test tasks for this test target.

There can be one to many instances of `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html` tasks for a particular test suite target. For instance, if the test suite targets more than one device, AGP may decide to create one `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html` instance per device.

The configuration block can use the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuite#configureTestTasks(kotlin.Function2)`'s context parameter to disambiguate between each `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html` task instance.

Do not make assumption about how AGP decides to allocate `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html` task instances per device, as each AGP version can potentially change it in future release, always use the context object to determine what the `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html` task applies to.

| Parameters |
|---|---|
| `action: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html.(context: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/TestTaskContext) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | a block to configure the `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html` tasks associated with this test suite target. Example : ``` androidComponents { onVariants { variant -> variant.testSuites.forEach { testSuite -> testSuite.configureTestTask { testTask -> testTask.beforeTest { descriptor -> println("Running test: " + descriptor) } } } } } ``` |
| `action: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html.(context: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/TestTaskContext) -> 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. |

### instrumentationRunner

Added in 9.6.0-alpha03

```
@Incubating
fun instrumentationRunner(source: TestSuiteSourceSet.TestApk): Provider<String>
```

The instrumentationRunner to use to run the tests.

| Returns |
|---|---|
| `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>` | the instrumentation test runner name |

### withTestTaskProviders

Added in 9.6.0-alpha03

```
@Incubating
fun withTestTaskProviders(action: TaskProvider<Test>.(context: TestTaskContext) -> Unit): Unit
```

Runs some action on the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuite` 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/TestSuite` is enabled. In particular the corresponding `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuiteBuilder#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 the configureTestTask method.

Example :

```
androidComponents {
    onVariants { variant ->
        variant.suites.forEach { suite ->
          suite.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>.(context: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/TestTaskContext) -> 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

### codeCoverageEnabled

Added in 9.6.0-alpha03

```
val codeCoverageEnabled: Boolean
```

Whether test coverage is enabled for this test suite.

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/TestSuiteBuilder#setEnabledCodeCoverage(kotlin.Boolean)` 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.

### junitEngineSpec

Added in 9.6.0-alpha03

```
val junitEngineSpec: JUnitEngineSpec
```

Return the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/JUnitEngineSpec` for this test suite.

### requiresUpdateTask

Added in 9.6.0-alpha03

```
val requiresUpdateTask: Provider<Boolean>
```

Whether this test suite requires an extra update task.

Initialized from the corresponding `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/AgpTestSuite#requiresUpdateTask()`

### sources

Added in 9.6.0-alpha03

```
val sources: Collection<TestSuiteSourceSet>
```

Return the list of sourcesets associated with this test suite. Sourcesets are added through the DSL using one of the following methods:

- `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/AgpTestSuite#assets(kotlin.Function1)`

- `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/AgpTestSuite#hostJar(kotlin.Function1)`

- `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/AgpTestSuite#testApk(kotlin.Function1)`

The returned `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/index.html` of `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuiteSourceSet` is not specific to this variant but to the related `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuite` instance, which may apply to multiple variants as specified through the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/AgpTestSuite#targetVariants()` API.

### targets

Added in 9.6.0-alpha03

```
val targets: Map<String, TestSuiteTarget>
```

Return the list of `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestSuiteTarget` for this test suite in this variant.