Skip to main content

Posts

Showing posts with the label android testing qa espresso

Writing ViewHolder Matcher with Espresso for Android.

Recently I had a need to adapt my Espresso tests to operate on RecyclerView after migration from ListViews. The current actions that are available for RecyclerView based on item position working fine but I don't like to be dependent on position since data in my tests is created dynamically. I've googled the ViewHolder matchers and found only this link without any practical examples -  RecyclerViewActions . Then based on already created Matcher<Object> used in onData(...) I've created Matcher<VH> which was not so difficult. Let's assume each item in RecyclerView adapter has subject, represented by TextView. The below matcher will search for item in RecylerView with unique subject which I provide into matcher. Feel free to use it: public static Matcher<RecyclerView.ViewHolder> withItemSubjectInViewHolder(final String itemSubject) { Checks.checkNotNull(itemSubject); return new BoundedMatcher (RecyclerView.ViewHolder, MyListRecyclerViewIt...

Tired of testing - take some Espresso!

Recently Google announced the new testing tool Espresso for Android - a simple API for writing reliable UI tests. So, I'd like to share with you some information about it and what I've experienced using it so far.  At first Espresso tool was not announced alone, it is used together with GoogleInstrumentationTestRunner - an improved InstrumentationTestRunner . That means that you have to claim it's usage in   AndroidManifest.xml   file of your test application and set it in test project   Run Configurations.     Espresso set up instructions are quite clear, at least for Eclipse IDE. If everything goes well you'll manage to run first test in 30 minutes.  Keep in mind following points which I hope will help you to save some time before starting: you have to check that your test project and project under test have no reused libraries. Most common one is  android-support-v4.jar . You have to remove them from test pro...