Slide 1

Slide 1 text

UI Testing on Android Mustafa Berkay Mutlu August 2nd 2017

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

View Matchers

Slide 8

Slide 8 text

View Actions

Slide 9

Slide 9 text

View Assertions

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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.

Slide 13

Slide 13 text

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' }

Slide 14

Slide 14 text

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.

Slide 15

Slide 15 text

Thank You