Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Efficient Android testing

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.

Alex Zhukovich

September 28, 2018
Tweet

More Decks by Alex Zhukovich

Other Decks in Technology

Transcript

  1. // 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()
  2. 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
  3. 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
  4. Search notes - scenarios Test scenario #1: Display all notes

    Test scenario #2: Handle error during loading notes Test scenario #3: Display search results
  5. 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
  6. Custom AndroidJUnitRunner class MockTestRunner : AndroidJUnitRunner() { override fun newApplication(cl:

    ClassLoader?, className: String?, context: Context?): Application { return Instrumentation.newApplication( MockMapNotesApp::class.java, context) } }
  7. Configuring product flavors productFlavors { prod { ... versionNameSuffix "-prod"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } dev { ... versionNameSuffix "-dev" testInstrumentationRunner "com.alex.mapnotes.MockTestRunner" } }
  8. 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