$30 off During Our Annual Pro Sale. View Details »

UI Testing on Android

UI Testing on Android

Mustafa Berkay Mutlu

August 02, 2017
Tweet

More Decks by Mustafa Berkay Mutlu

Other Decks in Programming

Transcript

  1. UI Testing on Android
    Mustafa Berkay Mutlu
    August 2nd 2017

    View Slide

  2. Android Testing Support Library
    ● Espresso
    ○ Concise, beautiful, and reliable Android UI tests
    ● Android JUnit Runner
    ○ JUnit4 support
    ○ Activity and Application life-cycle monitoring
    ○ Intent Monitoring and Stubbing
    ● JUnit4 Rules
    ○ More flexibility and reduced boilerplate code required in tests
    ● UI Automator
    ○ Cross-app functional UI testing across system and installed apps

    View Slide

  3. Anatomy of a UI Test
    1. Find a view
    2. Perform an action
    3. Inspect the result

    View Slide

  4. View Slide

  5. Espresso Framework
    Concise, beautiful, and reliable Android UI tests.
    The core API is small, predictable, and easy to
    learn and yet remains open for customization.
    @Test
    public void greeterSaysHello() {
    onView(withId( R.id.name_field))
    .perform(typeText( "Steve"));
    onView(withId( R.id.greet_button))
    .perform(click());
    onView(withText( "Hello Steve!" ))
    .check(matches(isDisplayed()));
    }

    View Slide

  6. Anatomy of a UI Test
    1. Find a view
    2. Perform an action
    3. Inspect the result
    onView(Matcher )
    .perform(ViewAction)
    .check(ViewAssertion );

    View Slide

  7. View Matchers

    View Slide

  8. View Actions

    View Slide

  9. View Assertions

    View Slide

  10. Espresso Test Recorder
    Lets you create UI tests for your app
    without writing any test code.

    View Slide

  11. Demo
    Let’s try Espresso Test Recorder and write some tests.

    View Slide

  12. Idling Resources
    Espresso detects when the main thread is idle.
    But it doesn’t know anything about other threads.
    Use Idling Resources to inform Espresso of the app’s idle/busy state.
    You can implement the IdlingResource interface yourself or use an
    already-existing implementation, such as CountingIdlingResource.

    View Slide

  13. Idling Resources
    Dependency note from Android docs:
    dependencies {
    ….
    // The following Espresso dependency can be either "compile"
    // or "androidTestCompile", depending on your app's implementation
    androidTestCompile 'com.android.support.test.espresso:espresso-idling-resource:3.0.0'
    }

    View Slide

  14. Firebase Test Lab for Android
    Test your app on devices hosted in a
    Google data center.
    Test results (logs, videos, and
    screenshots) are made available in the
    Firebase console.
    Free for 10 virtual device and 5 physical
    device executions daily.

    View Slide

  15. Thank You

    View Slide