test class - You can’t have Parameterized test if you’re using other class runner like AndroidTestRunner - We want to separate runner, reporting and so on into different interfaces
in") inner class WhenUserLoggedInTests { // ... test functions } @InnerTest @DisplayName("when user is logged out") inner class WhenUserLoggedOutTests { // ... test functions } }
Writing and executing Unit Tests on the JUnit Platform testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.2") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.11.2") // (Optional) If you need "Parameterized Tests" testImplementation("org.junit.jupiter:junit-jupiter-params:5.11.2") // (Optional) If you also have JUnit 4-based tests testImplementation("junit:junit:4.13.2") testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.11.2") }
ActivityScenarioExtension.launch<MyActivity>() @Test fun myTest() { val scenario = scenarioExtension.scenario // Do something with the scenario here... } }
to run instrumentation tests as it interacts with actual system API and it’s fast unlike running on actual emulators or real devices. It is also scalable with Firebase Test Lab!
device profiles you typically see in Android Studio. device = "Pixel 2" // Use only API levels 27 and higher. apiLevel = 30 // To include Google services, use "google". systemImageSource = "aosp" } } } }
and voice out if you have any https://issuetracker.google.com/issues/127100532 - Thumbs up on Robolectric open issue https://github.com/robolectric/robolectric/issues/3477 - Star android-junit5 library https://github.com/mannodermaus/android-junit5 - Start using Junit5 in your app