run-android-tests
run-android-tests copied to clipboard
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.
Running Android UI Tests
Blog posts
📗 Part 1 - https://medium.com/medisafe-tech-blog/running-android-ui-tests-53e85e5c8da8
- Building Execution Plan.
- Collect Logs, Record Video, Dump DB, Shared Preferences.
- Add ‘Clear data’ support.
- Add ‘Clear notifications’ support.
- Add parameterized support.
- Run tests by #tags.
- Dump network stats, battery, alarms and more.
- All together.
📗 Part 2 - https://medium.com/medisafe-tech-blog/running-android-ui-tests-part-2-15ef08056d94
- Parallel tests execution.
- Grouping following tests.
Test Options
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.
Test example
@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());
}
}
Artifacts
In addition to new added options, after each failed test, we fetching and building useful files that will help us investigate failed issues better.
- Recording (mp4)
- Logs
- DB (sqlite)
- Shared preferences
- Dumpsys - Netstats, battery, other.
Run this sample
Prepare:
- Clone the repo.
- Connect one or more real devices / emulators.
- Run on Mac / Ubuntu / Anything that has bash 3.2 (and above)
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
Detailed docs
- The flow and script
- Parallel — The regular approach vs. push approach
- Grouping following tests
Author
License
Apache 2.0