Tech Talk #5 : Android Automation Test with Espresso - Trần Văn Toàn

  • View
    240

  • Download
    0

  • Category

    Mobile

Preview:

Citation preview

Android Automation Test with Espresso

Trần Văn Toàn – vantoan@planday.com

Table Of Content

About Espresso Espresso Components Test case structure Custom Matcher and ViewAction

About Espresso An user interface testing framework for a

single application Run on devices running Android 2.2 and

higher The Espresso is an instrumentation-based API

and works with the AndroidJUnitRunner test

Espresso - Pros Reliable & synchronizes test actions with UI

operations (on the UI thread). open to customization with standard hamcrest

matchers Clear failure, rich debugging information.

Allows custom failure handler

Espresso - Cons

Does not support for WebView Slow speed since it run on Dalvik VM Work with Single application only. Solution: Using Espresso combine with uiautomator

Espresso Components ViewMatchers: find view based on: id, Tag,

description, text… withId(R.id.button)

ViewActions: perform actions on the views click(), scrollTo()

ViewAssertions: validate state of a view.matches(isDisplayed()), doesNotExist()

Test case structure

Find View Find the UI component under test in

an Activity by using the onView() or onData() method with a view matcher which selects the correct view.

Perform Actions Call perform() method and passing in the

user action defined by ViewActions class. Repeat the steps to simulate a user flow

across multiple activities in the target app

Validate the results Call check() method to check expected

state or behavior check() method requires a ViewAssertion

object as input

Custom Matcher & ViewAction Custom Matcher using BoundedMatcher or Hamcrest framework

Custom Matcher & ViewAction Custom Action by ViewAction class

THANK FOR WATCHING!!!

APPENDIX

Add Espresso to project install the Android Support Repository

Add Espresso to project Config project

Add Espresso to project Specify the AndroidJUnitRunner as value for the

testInstrumentationRunner

Construct Test Class and Methods

References documents

1. https://developer.android.com/training/testing/ui-testing/espresso-testing.html

2. https://google.github.io/android-testing-support-library/docs/espresso/

3. http://www.vogella.com/tutorials/AndroidTestingEspresso/article.html

4. http://hamcrest.org/JavaHamcrest/

Recommended