Running Android UI Tests - Collect logs, record a video, dump db, preferences and more. Clear data, run by tags and with params. Run in parallel. Easy extendable.
📗 Part 1 - https://medium.com/medisafe-tech-blog/running-android-ui-tests-53e85e5c8da8
📗 Part 2 - https://medium.com/medisafe-tech-blog/running-android-ui-tests-part-2-15ef08056d94
We write UI tests same as before. But now, we can add more annotations that will give us more options.Â
@ClearData
 - Clear data via ADB before test execution.@ClearNotifications
 - Clear notification bar via ADB before running the test.@Repeat
 - Repeat the same test X number of times, when current iteration is passed to the test.@Tags
 - You can tag your tests. Later, you can run tests by selected tags only.@Following
- Will enforce grouping following tests on the same device when running in parallel.@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Rule
public IntentsTestRule<MainActivity> mActivity = new IntentsTestRule<>(MainActivity.class);
private final String[] params = new String[]{
"a", "A", "Aa"
};
@Test
@ClearData
@Parameterized.Repeat(count = 3)
@Tags(tags = {"sanity", "small", "sample"})
public void someTest() throws Exception {
String param = params[Parameterized.getIndex()];
assertEquals("a", param.toLowerCase());
}
@Test
@Following
public void someTestFollowing() throws Exception {
assertEquals("a", "A".toLowerCase());
}
}
In addition to new added options, after each failed test, we fetching and building useful files that will help us investigate failed issues better.
Prepare:
Run:
# ---- assemble and install the app + test apks ----
# build app APK
./gradlew assembleDebug --stacktrace
# build test APK
./gradlew assembleAndroidTest --stacktrace
# install app APK
adb install -r app/build/outputs/apk/app-debug.apk
# install test APK
adb install -r app/build/outputs/apk/app-debug-androidTest.apk
# ---- prepare and run the tests ----
# create tests raw file
./scripts/raw.sh artifacts/raw-tests.txt
# build execution plan and filter by tags
./scripts/plan.sh artifacts/raw-tests.txt artifacts/execution-plan.txt
# run the tests
./scripts/run.sh artifacts/execution-plan.txt artifacts
Apache 2.0