Using Android Test Orchestrator
The Android Test Orchestrator is a tool which allows developers to execute the contents of their instrumentation test suite in isolation. Each test is executed on a separate test runner. This helps with state separation in-between tests, and might improve stability of the execution.
The JUnit 5 instrumentation test libraries are compatible with the Orchestrator, although it currently requires a little bit of additional setup to get working. Namely, your JUnit 5 instrumentation test classes must be annotated with JUnit's @UseTechnicalNames annotation. You can get access to this annotation from the following dependency; add it to your build script and sync your project:
dependencies {
androidTestImplementation("org.junit.platform:junit-platform-suite-api:1.7.2")
}Next, annotate your test class with @UseTechnicalNames:
@UseTechnicalNames class MyActivityTest { @JvmField @RegisterExtension val extension = ActivityScenarioExtension.launch<MyActivity>() // ... }