tech talk #5 : android automation test with espresso - trần văn toàn

19
Android Automation Test with Espresso Trần Văn Toàn – [email protected]

Upload: innovatube

Post on 16-Apr-2017

240 views

Category:

Mobile


0 download

TRANSCRIPT

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

Android Automation Test with Espresso

Trần Văn Toàn – [email protected]

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

Table Of Content

About Espresso Espresso Components Test case structure Custom Matcher and ViewAction

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

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

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

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

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

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

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

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

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

Test case structure

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

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.

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

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

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

Validate the results Call check() method to check expected

state or behavior check() method requires a ViewAssertion

object as input

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

Custom Matcher & ViewAction Custom Matcher using BoundedMatcher or Hamcrest framework

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

Custom Matcher & ViewAction Custom Action by ViewAction class

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

THANK FOR WATCHING!!!

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

APPENDIX

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

Add Espresso to project install the Android Support Repository

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

Add Espresso to project Config project

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

Add Espresso to project Specify the AndroidJUnitRunner as value for the

testInstrumentationRunner

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

Construct Test Class and Methods

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

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/