Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

Android Automation Test with Espresso

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Login to see the comments

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

  1. 1. Android Automation Test with Espresso Trần Văn Toàn – vantoan@planday.com
  2. 2. Table Of Content  About Espresso  Espresso Components  Test case structure  Custom Matcher and ViewAction
  3. 3. 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
  4. 4. 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
  5. 5. 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
  6. 6. 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()
  7. 7. Test case structure
  8. 8. 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.
  9. 9. 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
  10. 10. Validate the results  Call check() method to check expected state or behavior  check() method requires a ViewAssertion object as input
  11. 11. Custom Matcher & ViewAction Custom Matcher using BoundedMatcher or Hamcrest framework
  12. 12. Custom Matcher & ViewAction Custom Action by ViewAction class
  13. 13. THANK FOR WATCHING!
  14. 14. APPENDIX
  15. 15. Add Espresso to project  install the Android Support Repository
  16. 16. Add Espresso to project  Config project
  17. 17. Add Espresso to project  Specify the AndroidJUnitRunner as value for the testInstrumentationRunner
  18. 18. Construct Test Class and Methods
  19. 19. 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/artic le.html 4. http://hamcrest.org/JavaHamcrest/

×