How to Use Espresso v2.0 on Bitbar Testing

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. Let’s check it out – it’s a great promising framework for your app testing! And it’s FAAAAST!

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 a 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 on Bitbar Testing

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

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 Bitbar Testing. 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 Bitbar Testing) define the custom test runner in this view, as shown on the 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 a few minutes!


You can now run your tests directly from Android Studio using Bitbar’s 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 Bitbar Testing devices in your testing and many other test automation specific detail, do check out webinar and slidedeck about this great-potential framework!

Happy Testing!Espresso Cheat Sheet by Google

Manifesto: Everything about Mobile DevOps

Learn how to properly adopt DevOps approach for your mobile team and get the most out of it.


  • 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