Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

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

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

    Perform an action 3. Inspect the result onView(Matcher<View> ) .perform(ViewAction) .check(ViewAssertion );
  5. 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.
  6. 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' }
  7. 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.