I\'m trying to use Espresso. But I got this error and I have no if I\'m missing some codes.
any thoughts will be highly appreciated.
error log:
You are missing a GoogleInstrumentationTestRunner entry in your manifest. After that, make sure to configure your tests to run through GITR. See instructions here: https://code.google.com/p/android-test-kit/wiki/Espresso#Espresso_Setup_Instructions
Your value of instrumentation->android:name should be "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" not "android.test.InstrumentationTestRunner".
And then be sure to select it when configuring your junit test:
I posted a quick setup tut on my blog if you need more guidance.
To clarify the instructions on https://code.google.com/p/android-test-kit/wiki/Espresso#Espresso_Setup_Instructions, referenced by @ValeraZakharov
When using Android Studio and gradle, there is no need to update AndroidManifest.xml, instead the file build.gradle
needs to be edited. Add this entry to the section android
- defaultConfig
:
android {
defaultConfig {
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
}
Also: Right-click "add as a library" has been removed from Android studio, and replaced with:
android {
sourceSets {
// Espresso instrumentation tests
androidTest.setRoot('src/instrumentTest')
}
}
The complete section android
looks like this in my project:
android {
compileSdkVersion 17
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 16
versionName getCommitNumber()
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
sourceSets {
// Espresso instrumentation tests
androidTest.setRoot('src/instrumentTest')
}
packagingOptions {
// Multiple LICENSE.txt in hamcrest packages.
exclude 'LICENSE.txt'
}
}
If you have a dependent library with unit test applied, the libary should have same instrument setup also as below.
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
You should use GoogleInstrumentationTestRunner, as others mentioned. If you build with ant, You need to add an element to the "project" directive in build.xml of the Test Project like below.
in build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="MainActivityTest" default="help">
...
<property name="test.runner" value="com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" />
</project>