Recently Google announced the new testing tool Espresso for Android - a simple API for writing reliable UI tests. So, we'd like to share with you some information about it and what we'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 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 project. Having jars in both projects will lead to below issue
set up for every test Run->Edit Configurations with GoogleInstrumentationTestRunner if you'd like to run concrete test from your project.
there is no support of testing navigation drawer element yet but under this link you can find a workaround. Seems that official support of this feature will be added soon.
if the element you want to perform action on is not visible on device screen - you have to scroll to it first or, in case of lists, use
waitForActivityanymore, Espresso will handle this for you.
possibility to write multiply instructions for one element in one command:
onView(withId(is(R.id.edit_password))).perform( scrollTo(), click(), typeText(password), closeSoftKeyboard());
onData()command you must implement matchers by yourself, but when you got how to do it they become the real powerful tool for you.
Summarizing all above I'd like to say that at first glance it seems that Espresso's API is clear and understandable but after some time you understand that it requires deeper development knowledge. Seems that Espresso is targeting more developers audience than testers.
And taking into consideration that Google takes care of it, this tool probably will grow as a snow ball in the nearest feature.