BackupRestoreExtension


class BackupRestoreExtension : BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback, ParameterResolver


A JUnit 5 Jupiter extension that resolves BackupRestoreController test parameters.

It automatically initializes ADB sessions, selects an online Android device matching target API and serial constraints (specified via system properties or Device annotations), handles automatic APK installation for tested and test packages, proactively dismisses lockscreens/keyguards, and sets up data isolation (e.g. running pm clear) prior to test execution.

Each controller targets the app named by the test class's BackupRestoreConfig. Without one, it targets the tested app that the test suite properties name.

When a test fails, the extension saves the logs of each device that the test used while it ran, and names the saved files in the test failure. Logs aren't saved for aborted tests, such as a failed assumption. To also save them when a @BeforeAll or @AfterAll method fails, register the extension on the test class, with @ExtendWith or a static @RegisterExtension field. To turn off saving logs, set the system property androidx.test.backup.device.logs.enabled to false. To also save device logs when tests pass, set androidx.test.backup.report.captureLogcatOnPass to true; to copy raw backup archives into the report artifacts, set androidx.test.backup.report.includeRawArchives to true.

The files are published as JUnit file attachments when the JUnit Platform version supports them, or else saved in a new temporary directory that the extension keeps after the test run.

Summary

Public constructors

Creates an extension, which manages its own ADB session.

Public functions

open Unit
open Unit
open Unit
open Unit
open Any
resolveParameter(
    parameterContext: ParameterContext,
    extensionContext: ExtensionContext
)
open Boolean
supportsParameter(
    parameterContext: ParameterContext,
    extensionContext: ExtensionContext
)

Public constructors

BackupRestoreExtension

Added in 1.0.0-alpha06
BackupRestoreExtension()

Creates an extension, which manages its own ADB session.

All extensions in a test run share one session. It is created when a test first requests a BackupRestoreController and closed when the test run ends.

Public functions

afterAll

Added in 1.0.0-alpha06
open fun afterAll(context: ExtensionContext): Unit

afterEach

Added in 1.0.0-alpha06
open fun afterEach(context: ExtensionContext): Unit

beforeAll

Added in 1.0.0-alpha06
open fun beforeAll(context: ExtensionContext): Unit

beforeEach

Added in 1.0.0-alpha06
open fun beforeEach(context: ExtensionContext): Unit

resolveParameter

Added in 1.0.0-alpha06
open fun resolveParameter(
    parameterContext: ParameterContext,
    extensionContext: ExtensionContext
): Any

supportsParameter

Added in 1.0.0-alpha06
open fun supportsParameter(
    parameterContext: ParameterContext,
    extensionContext: ExtensionContext
): Boolean