From your mistake, it seems that you are not including the espresso libraries. The solution to this is to add the main espresso library, which is part of the Android testing support library hosted in the Google Maven repository, consider this a kind of git repository, but for dependencies.
So, we tell the gradle build system to look in the Maven repository for dependencies by specifying its URL.
This is done by adding the Maven URL to the build.gradle application level file in the repository block
repositories { jcenter() maven{ url "https://maven.google.com" } }
and in the build.gradle file at the module level, specify the dependencies that you want from the maven repository, specifying their name as follows:
dependencies{ //other dependencies go here //testing dependencies androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1' }
This is the reason for including the Maven repository URL in the application level build.gradle file, hope this helps.
source share