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

    View Slide

  2. View Slide

  3. View Slide

  4. Setup
    Execution
    Verification
    Clean up

    View Slide

  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()

    View Slide

  6. Android tests
    Local Instrumentation
    UI Non-UI
    Robolectric
    Espresso
    UiAutomator
    Appium
    Instrumentation API

    View Slide

  7. UiAutomatorViewer
    Testing Android toolset

    View Slide

  8. LayoutInspector
    Testing Android toolset

    View Slide

  9. Installing and running test cases on device
    adb shell
    Instrumentation
    am instrument
    Application
    Test Application

    View Slide

  10. Moving to
    test samples

    View Slide

  11. Application overview

    View Slide

  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

    View Slide

  13. Authorization of the user – E2E

    View Slide

  14. Authorization of the users – UI with mocking
    DATA

    View Slide

  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

    View Slide

  16. Search notes - scenarios
    Test scenario #1:
    Display all notes
    Test scenario #2:
    Handle error during loading notes
    Test scenario #3:
    Display search results

    View Slide

  17. Displaying all notes – E2E

    View Slide

  18. Handle error during loading notes – E2E
    !

    View Slide

  19. Display search results – E2E

    View Slide

  20. Display all notes – UI with mocking
    DATA

    View Slide

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

    View Slide

  22. Display search results – UI with mocking
    DATA

    View Slide

  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

    View Slide

  24. Should we use UI test with mocking
    everywhere?

    View Slide

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

    View Slide

  26. Scope of Regression testing

    View Slide

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

    View Slide

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

    View Slide

  29. Integration with
    an Android app

    View Slide

  30. Custom AndroidJUnitRunner
    class MockTestRunner : AndroidJUnitRunner() {
    override fun newApplication(cl: ClassLoader?,
    className: String?,
    context: Context?): Application {
    return Instrumentation.newApplication(
    MockMapNotesApp::class.java,
    context)
    }
    }

    View Slide

  31. Configuring product flavors
    productFlavors {
    prod {
    ...
    versionNameSuffix "-prod"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    dev {
    ...
    versionNameSuffix "-dev"
    testInstrumentationRunner "com.alex.mapnotes.MockTestRunner"
    }
    }

    View Slide

  32. Testing tips

    View Slide

  33. The name matters

    View Slide

  34. Learn existing test cases
    and maintain them

    View Slide

  35. Verify positive and negative
    test cases

    View Slide

  36. Verify business and
    navigation flows

    View Slide

  37. Test only your code

    View Slide

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

    View Slide

  39. Stop testing manually, just
    automate it

    View Slide

  40. Care about testability in the
    code

    View Slide

  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

    View Slide