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. Efficient Android testing @Alex_Zhukovich

  2. None
  3. None
  4. Setup Execution Verification Clean up

  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()
  6. Android tests Local Instrumentation UI Non-UI Robolectric Espresso UiAutomator Appium

    Instrumentation API
  7. UiAutomatorViewer Testing Android toolset

  8. LayoutInspector Testing Android toolset

  9. Installing and running test cases on device adb shell Instrumentation

    am instrument Application Test Application
  10. Moving to test samples

  11. Application overview

  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
  13. Authorization of the user – E2E

  14. Authorization of the users – UI with mocking DATA

  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
  16. Search notes - scenarios Test scenario #1: Display all notes

    Test scenario #2: Handle error during loading notes Test scenario #3: Display search results
  17. Displaying all notes – E2E

  18. Handle error during loading notes – E2E !

  19. Display search results – E2E

  20. Display all notes – UI with mocking DATA

  21. Handle error during loading notes – UI with mocking DATA

  22. Display search results – UI with mocking DATA

  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
  24. Should we use UI test with mocking everywhere?

  25. Should we use UI tests with mocking everywhere? https://gph.is/1bkaInz

  26. Scope of Regression testing

  27. E2E test cases in scope of regression tests Specifications Analytical

    data
  28. Efficient UI testing End To End tests UI tests +

  29. Integration with an Android app

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

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

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } dev { ... versionNameSuffix "-dev" testInstrumentationRunner "com.alex.mapnotes.MockTestRunner" } }
  32. Testing tips

  33. The name matters

  34. Learn existing test cases and maintain them

  35. Verify positive and negative test cases

  36. Verify business and navigation flows

  37. Test only your code

  38. Write test case base on specification, not on implementation

  39. Stop testing manually, just automate it

  40. Care about testability in the code

  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