BackupRestoreExtension


public final class BackupRestoreExtension implements 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.

The files are in suite-details in the results directory of the test suite. Outside of a test suite, they are in a new temporary directory, which the extension keeps after the test run.

Summary

Public constructors

Creates an extension, which manages its own ADB session.

Public methods

void
void
void
void
@NonNull Object
resolveParameter(
    ParameterContext parameterContext,
    ExtensionContext extensionContext
)
boolean
supportsParameter(
    ParameterContext parameterContext,
    ExtensionContext extensionContext
)

Public constructors

BackupRestoreExtension

Added in 1.0.0-alpha04
public 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 methods

afterAll

Added in 1.0.0-alpha04
public void afterAll(@NonNull ExtensionContext context)

afterEach

Added in 1.0.0-alpha04
public void afterEach(@NonNull ExtensionContext context)

beforeAll

Added in 1.0.0-alpha04
public void beforeAll(@NonNull ExtensionContext context)

beforeEach

Added in 1.0.0-alpha04
public void beforeEach(@NonNull ExtensionContext context)

resolveParameter

Added in 1.0.0-alpha04
public @NonNull Object resolveParameter(
    ParameterContext parameterContext,
    ExtensionContext extensionContext
)

supportsParameter

Added in 1.0.0-alpha04
public boolean supportsParameter(
    ParameterContext parameterContext,
    ExtensionContext extensionContext
)