Code Monkey home page Code Monkey logo

run-android-tests's Introduction

Running Android UI Tests

Blog posts

📗 Part 1 - https://medium.com/medisafe-tech-blog/running-android-ui-tests-53e85e5c8da8

  1. Building Execution Plan.
  2. Collect Logs, Record Video, Dump DB, Shared Preferences.
  3. Add ‘Clear data’ support.
  4. Add ‘Clear notifications’ support.
  5. Add parameterized support.
  6. Run tests by #tags.
  7. Dump network stats, battery, alarms and more.
  8. All together.

📗 Part 2 - https://medium.com/medisafe-tech-blog/running-android-ui-tests-part-2-15ef08056d94

  1. Parallel tests execution.
  2. 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:

  1. Clone the repo.
  2. Connect one or more real devices / emulators.
  3. 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

Author

Roman Kushnarenko - sromku

License

Apache 2.0

run-android-tests's People

Contributors

sromku avatar joekiller avatar

Watchers

Dat Nguyen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.