Efficient Android testing

2b0404a5db1a74f01bf3bf94d142e28c?s=47 Alex Zhukovich
September 28, 2018

Efficient Android testing

Mobile applications are growing. They become more complex and require more and more testing on different layers. It means that is a great time to integrate automated tests into your projects. When we talk about the testing of User Interface many people choose End-To-End tests. In the beginning, it works well, but later on, when the code base grows, you can have a very slow feedback loop.
This talk will cover:
- the difference between Integration and End-To-End tests;
- Tools we can use in terms of UI testing;
- Methods for the efficient combination of different levels of tests;
- Efficient testing using Espresso and UiAutomator.

2b0404a5db1a74f01bf3bf94d142e28c?s=128

Alex Zhukovich

September 28, 2018
Tweet

Transcript

  1. 2.
  2. 3.
  3. 5.

    // setup var note = Note(“Hi!”, WARSAW_LAT, WARSAW_LON) // execution

    database.insert(note) // verification var result = database.getNotes() assertEquals(EXPECTED_NOTES, result) // clean up clearDatabase()
  4. 9.
  5. 12.

    Authorization of the user - scenarios Test scenario #1: Enter

    correct auth data Test scenario #2: Enter incorrect auth data Test scenario #3: Enter incorrect auth data and handle them on client side
  6. 15.

    Authorization of the user – differences End-To-End test cases UI

    tests with mocking B Interaction with server Verification interaction with a server C Fast UI verification Fast and independent on resources tests A Entry point Start tests from the main screen B No interaction with server Verification UI and interaction with mock object A Entry point Start test from any screen of the app
  7. 16.

    Search notes - scenarios Test scenario #1: Display all notes

    Test scenario #2: Handle error during loading notes Test scenario #3: Display search results
  8. 23.

    Search notes – differences End-To-End test cases UI tests cases

    with mocking B Interaction with server Verification interaction with a server A Entry point Start tests from the main screen C Data from the server Depend on data from the server E Fast UI verification Fast and independent on resources tests B No interaction with server Verification UI and interaction with mock object A Entry point Start test from any screen of the app D App architecture Architecture should support mocking C UI component verification Testing only fragments, view without main Activity
  9. 30.

    Custom AndroidJUnitRunner class MockTestRunner : AndroidJUnitRunner() { override fun newApplication(cl:

    ClassLoader?, className: String?, context: Context?): Application { return Instrumentation.newApplication( MockMapNotesApp::class.java, context) } }
  10. 31.

    Configuring product flavors productFlavors { prod { ... versionNameSuffix "-prod"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } dev { ... versionNameSuffix "-dev" testInstrumentationRunner "com.alex.mapnotes.MockTestRunner" } }
  11. 41.

    Q&A Espresso: https://developer.android.com/training/testing/espresso/ UiAutomator: https://developer.android.com/training/testing/ui-automator/ Appium: http://appium.io/ Android Testing codelab:

    https://codelabs.developers.google.com/codelabs/android-testing/ MapNotes: https://github.com/AlexZhukovich/MapNotes Blog: http://alexzh.com/ @Alex_Zhukovich