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

UI Testing on Android

UI Testing on Android

Da49bf507d07666987c1546e894dee8d?s=128

Mustafa Berkay Mutlu

August 02, 2017
Tweet

Transcript

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

  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
  3. Anatomy of a UI Test 1. Find a view 2.

    Perform an action 3. Inspect the result
  4. None
  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())); }
  6. Anatomy of a UI Test 1. Find a view 2.

    Perform an action 3. Inspect the result onView(Matcher<View> ) .perform(ViewAction) .check(ViewAssertion );
  7. View Matchers

  8. View Actions

  9. View Assertions

  10. Espresso Test Recorder Lets you create UI tests for your

    app without writing any test code.
  11. Demo Let’s try Espresso Test Recorder and write some tests.

  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.
  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' }
  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.
  15. Thank You