File this under “I’m writing this so when I Google for it in 6 months, it pops up”.
I recently set up an existing Android project with Espresso 2.0 and immediately stared running into this error when I ran the tests:
Running tests Test running started Test running failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException' Empty test suite.
I spent some time last night fighting this error and then I figured out the solution this morning.
The problem is that I’m using Dagger in this project and Espresso 2.0 also uses Dagger (see Espresso Dependencies). The core problem is that the ‘javax.inject’ dependency was borking the test run.
How to to Fix
Change this
androidTestCompile('com.android.support.test.espresso:espresso-core:2.0')
to this:
androidTestCompile('com.android.support.test.espresso:espresso-core:2.0') { exclude group: 'javax.inject' }
Problem solved.
Bryant says
Thank you!
Mark OBrien says
Just saved me a night of trying to figure this out. Tests running now. Thanks
Donn Felker says
No problem. 🙂 Glad it helped.
Donn Felker says
NP!
Brian says
actually, i want to know the way you find the problem
Sharma Hitesh says
Even after excluding java.inject in manifest file, i am still facing this issue. Getting following error now “Execution failed for task ‘:dexArmDebugAndroidTest’.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java” finished with non-zero exit value 1″
Stas Shakirov says
Not helped for me.
“`
ext {
junitVersion = ‘4.12’
hamcrestVersion = ‘1.3’
runnerVersion = ‘0.5’
rulesVersion = ‘0.5’
espressoVersion = ‘2.2.2’
googlePlayServiceVersion = “8.4.0”
supportVersion = “23.4.0”
}
“`
ChunLun Kuo says
You save me a week ! Thanks!!!!!!!!!!!!!!!!!!
vishal says
Hi I have tried this but still get same issue
below are my gradle
dependencies {
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
compile ‘com.android.support:recyclerview-v7:23.1.1’
compile ‘com.android.support:appcompat-v7:23.1.1’
compile ‘com.android.volley:volley:1.+’
compile “com.squareup.picasso:picasso:2.4.0”
compile ‘com.android.support:multidex:1.0.0’
testCompile ‘junit:junit:4.12’
// Android runner and rules support
androidTestCompile ‘com.android.support.test:runner:0.5’
androidTestCompile ‘com.android.support.test:rules:0.5’
// Espresso support
androidTestCompile (‘com.android.support.test.espresso:espresso-contrib:2.2’){
exclude group: ‘com.android.support’, module: ‘appcompat-v7’
exclude group: ‘com.android.support’, module: ‘support-v4’
exclude module: ‘recyclerview-v7’
exclude group: “javax.inject”
exclude group: ‘com.google.guava’
}
androidTestCompile(‘com.android.support:multidex-instrumentation:1.0.1’) {
exclude group: ‘com.android.support’, module: ‘multidex’
}
// add this for intent mocking support
androidTestCompile ‘com.android.support.test.espresso:espresso-intents:2.2.2’
// add this for webview testing support
androidTestCompile ‘com.android.support.test.espresso:espresso-web:2.2.2’
androidTestCompile ‘com.android.support.test.espresso:espresso-contrib:2.2.2’
}
and want to move from splash to navigation drawer but not recognize my navigation activity and give java.lang.NoClassDefFoundError: please help