# BackupTestSuite

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


```
@Incubating
interface BackupTestSuite
```

<br />

*** ** * ** ***

A test suite to configure and run Automated Backup and Restore tests.

A `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/BackupTestSuite` configures the execution environment, JUnit 5 test engine, instrumentation runners, and dual source container dependency graphs required to execute automated backup and restore tests on a target device or emulator.

Automated Backup and Restore testing uses a hybrid orchestration model:

1. **Host-side test orchestrator (configured via `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/BackupTestSuite#hostJar(kotlin.Function1)`)**: Executes on the host machine (JVM) using JUnit 5 (Jupiter), driving device state via ADB, triggering cloud or local backup passes, clearing app data, initiating restores, and verifying broadcast signals.

2. **On-device test harness (configured via `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/BackupTestSuite#testApk(kotlin.Function1)`)**: Runs inside an instrumented Android environment to seed local storage state (SharedPreferences, Room/SQLite, files, Keystore) prior to backup, and asserts post-restore data integrity.

Example usage:

```
android {
    testOptions {
        backupTests {
            create("myBackupTest") {
                backupTestLibraryVersion = "1.0.0-alpha01"
                targetVariants.add("debug")

                hostJar {
                    dependencies {
                        implementation(project(":custom-backup-test-helpers"))
                        implementation("com.google.truth:truth:1.4.2")
                    }
                }
                testApk {
                    dependencies {
                        implementation("androidx.room:room-testing:2.6.1")
                    }
                }
            }
        }
    }
}
```

## 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/dsl/BackupTestSuite#hostJar(kotlin.Function1)(action: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/TestSuiteHostJarSpec.() -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` Configures the host-side (JVM) test component for this test suite. |
| `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/dsl/BackupTestSuite#testApk(kotlin.Function1)(action: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/TestSuiteTestApkSpec.() -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` Configures the on-device (APK) test component for this test suite. |

| ### Public properties |
|---|---|
| `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/dsl/BackupTestSuite#backupTestLibraryVersion()` The version of the automated backup test framework. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/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/dsl/BackupTestSuite#targetVariants()` Defines which build variants this test suite targets. |

## Public functions

### hostJar

Added in 9.6.0-alpha03

```
@Incubating
fun hostJar(action: TestSuiteHostJarSpec.() -> Unit): Unit
```

Configures the host-side (JVM) test component for this test suite.

Dependencies declared inside this block are added to the host JVM test execution classpath. This enables host-side tests to access custom test helpers, assertion libraries (e.g., Google Truth), and mock frameworks.

| Parameters |
|---|---|
| `action: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/TestSuiteHostJarSpec.() -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | Lambda to configure the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/TestSuiteHostJarSpec`. |

### testApk

Added in 9.6.0-alpha03

```
@Incubating
fun testApk(action: TestSuiteTestApkSpec.() -> Unit): Unit
```

Configures the on-device (APK) test component for this test suite.

Dependencies declared inside this block are compiled into the on-device test helper APK. This enables on-device actions to access application database schemas, Room testing utilities, and custom instrumentation runners.

| Parameters |
|---|---|
| `action: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/TestSuiteTestApkSpec.() -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | Lambda to configure the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/TestSuiteTestApkSpec`. |

## Public properties

### backupTestLibraryVersion

Added in 9.6.0-alpha03

```
var backupTestLibraryVersion: String?
```

The version of the automated backup test framework.

Specifies the version of the `androidx.test.backup:backup-host` and `androidx.test.backup:backup` artifacts to automatically inject into the test suite's host and device execution classpaths.

This property is optional. If omitted, the Android Gradle Plugin will default to the latest compatible framework version.

### targetVariants

Added in 9.6.0-alpha03

```
val targetVariants: MutableList<String>
```

Defines which build variants this test suite targets.

If left empty, all buildable variants in the module will be tested.