How to Use Espresso v2.0 with Testdroid Cloud Devices

Dear Testdroiders,

Google recently released a long-awaited new version of Espresso (known as v2.0 now). Even the first version sparked some noticeable interest among test automation community, it seems that the second version is a great improvement and should be definitely checked out by everyone who uses Espresso as their test automation framework.

We’ve been providing support for the first version of Espresso about a year now – and now officially for v2.0. Check it out – it’s great promising framework for your app testing! And it’s FAAAAST!

Espresso and Testdroid

Getting Started – with Android Studio and Espresso v2.0

Espresso v2.0 seems to work fine with both Android SDK on Eclipse and Android Studio, but as Google recommends Android Studio we’re providing the instructions here for Android Studio.

In order to get Espresso v2.0 properly configured, follow these steps:

1) Open the SDK Manager (under Tools -> Android -> SDK Manager):

SDK Manager

2) Ensure you have the Android Support Repository installed. This can be found under Extras.

Android Support Repository

3) Open build.gradle file (under file structure app/build.gradle) in text editor.

4) Add the following piece of code inside dependencies:

androidTestCompile ''
androidTestCompile ''

In addition, if your application uses functionalities from espresso-contrib, add the following line inside dependencies:

androidTestCompile ''

5) Configure the instrumentation runner with the testInstrumentationRunner. It should look like this:

Set Instrumentationrunner properlyMore information about Espresso Core Resource can be found in this Javadoc.

The New Test Runner – AndroidJUnitRunner

The AndroidJUnitRunner is a new unbundled test runner for Android, which is part of the Android Support Test Library and can be downloaded via the Android Support Repository. The new runner contains all improvements of GoogleInstrumentationTestRunner and adds more features, such as:

  • JUnit4 support
  • Instrumentation Registry for accessing InstrumentationContext and Bundle Arguments
  • Test Filters @SdkSupress and @RequiresDevice
  • Test timeouts
  • Sharding of tests
  • RunListener support to hook into the test run lifecycle
  • Activity monitoring mechanism ActivityLifecycleMonitorRegistry

The User Guide for AndroidJUnitRunner can be found here.

How to use Espresso v2.0 tests at Testdroid Cloud

Let’s take a look how to run your Espresso scripts at Testdroid Cloud. Follow these few steps and you should get your app up and running

So, how you can run tests written with this cool new framework in Testdroid Cloud? Just few steps and you’ll get your app tested with this framework on hundreds of real Android devices:

Step #1:

First, you have to create a test configuration in Android Studio. Open Run -> Edit Configurations. Click ‘+’ button on the left-top corner to add new configuration as Android Tests. Give a name to test configuration (here ‘New Test Config’), select module (here ‘app’) and specify the instrumentation runner (here ‘’). Your open Run/Debug Configuration dialog should look this this:

Run/Debug Configuration
Now, your environment should be properly configured to build instrumentation packages.

Step #2:

Once you have configured the test project you can build it and upload into Testdroid Cloud. Under test run creation, create a standard “Android” project, upload your application APK, upload your test APK, select device group as you wish, and under Advanced configuration (step #4 in Testdroid Cloud) define the custom test runner in this view, as shown on screenshot below:

Configuring the custom test runner in Testdroid Cloud

NOTE! The above dialog doesn’t show the whole string but it should be naturally –

Step #3:

Start your test and the test results will be ready in few minutes!


You can now run your tests directly from Android Studio using Testdroid Gradle plugin! This awesome plugin eliminates the need for any manual effort in order to build and get your APK up and running on physical devices. Check it out – it’s simply awesome!

Also, if you are interested to check out more good stuff about Esprosso, how to write tests with it, how to fully utilize our Testdroid Cloud devices in your testing and many other test automation specific detail, do check out webinar and slidedeck about this great-potential framework!

Espresso Webinar

Happy Testing!

Espresso Cheat Sheet by Google

Highway to Mobile Game & App Success in China

Learn how to win and generate revenue from the competitive and crowded Chinese mobile market


  • Jyotman Singh

    How can we disable device Animations on your cloud devices?

  • Orange Munni

    How can i get the build.gradle file.Can you send me the exact path in android folder