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 full-size slide

  2. Setup
    Execution
    Verification
    Clean up

    View full-size slide

  3. // 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 full-size slide

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

    View full-size slide

  5. UiAutomatorViewer
    Testing Android toolset

    View full-size slide

  6. LayoutInspector
    Testing Android toolset

    View full-size slide

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

    View full-size slide

  8. Moving to
    test samples

    View full-size slide

  9. Application overview

    View full-size slide

  10. 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 full-size slide

  11. Authorization of the user – E2E

    View full-size slide

  12. Authorization of the users – UI with mocking
    DATA

    View full-size slide

  13. 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 full-size slide

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

    View full-size slide

  15. Displaying all notes – E2E

    View full-size slide

  16. Handle error during loading notes – E2E
    !

    View full-size slide

  17. Display search results – E2E

    View full-size slide

  18. Display all notes – UI with mocking
    DATA

    View full-size slide

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

    View full-size slide

  20. Display search results – UI with mocking
    DATA

    View full-size slide

  21. 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 full-size slide

  22. Should we use UI test with mocking
    everywhere?

    View full-size slide

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

    View full-size slide

  24. Scope of Regression testing

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  27. Integration with
    an Android app

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  30. Testing tips

    View full-size slide

  31. The name matters

    View full-size slide

  32. Learn existing test cases
    and maintain them

    View full-size slide

  33. Verify positive and negative
    test cases

    View full-size slide

  34. Verify business and
    navigation flows

    View full-size slide

  35. Test only your code

    View full-size slide

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

    View full-size slide

  37. Stop testing manually, just
    automate it

    View full-size slide

  38. Care about testability in the
    code

    View full-size slide

  39. 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 full-size slide