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!
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):
2) Ensure you have the Android Support Repository installed. This can be found under Extras.
build.gradle file (under file structure
app/build.gradle) in text editor.
4) Add the following piece of code inside dependencies:
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0' androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
In addition, if your application uses functionalities from
espresso-contrib, add the following line inside dependencies:
5) Configure the instrumentation runner with the
testInstrumentationRunner. It should look like this:
More 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 Instrumentation, Context 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:
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 ‘android.support.test.runner.AndroidJUnitRunner’). Your open Run/Debug Configuration dialog should look this this:
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:
NOTE! The above dialog doesn’t show the whole string but it should be naturally – android.support.test.runner.AndroidJUnitRunner
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!
Learn tips & tricks to build better games and make users’ lives more enjoyable.Download