user1796624 February 2016

Espresso test aren't running after adding espresso-contrib library in gradle

When I'm adding the

androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'

in the gradle and run an Espresso test, I get the following error:

 Testing started at 5:59 PM ...

02/08 17:59:58: Launching changeText_sameAct...()
No apk changes detected since last installation, skipping installation of /Users/xxx/Documents/home/MasterDetails/app/build/outputs/apk/app-debug.apk
$ adb shell am force-stop databinding.com.masterdetails
No apk changes detected since last installation, skipping installation of /Users/xxx/Documents/home/MasterDetails/app/build/outputs/apk/app-debug-androidTest-unaligned.apk
$ adb shell am force-stop databinding.com.masterdetails.test
Running tests

$ adb shell am instrument -w -r   -e debug false -e class databinding.com.masterdetails.TestPostListActivity#changeText_sameActivity databinding.com.masterdetails.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..Waiting for process to come online
Connected to process 10355 on device samsung-sm_g920f-01157df1bc4b5336
Test running started

java.lang.IncompatibleClassChangeError: databinding.com.masterdetails.PostListActivity
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:226)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
at dalvik.system.DexPathList.findClass(DexPathList.java:321)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at databinding.com.masterdetails.TestPostListActivity.<init>(TestPostListActivity.java:25)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflec        

Answers


denys February 2016

Seems that you include RecyclerView component twice: here - compile 'com.android.support:recyclerview-v7:23.1.1' and here androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'. Add below code in your build.gradle after dependencies section and try again:

configurations {
    androidTestCompile.exclude group: 'com.android.support', module: 'recyclerview-v7'
}


piotrek1543 February 2016

Please check my dependendecies, especially espresso ones.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    androidTestCompile "com.android.support:support-annotations:$ASVersion"
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude module: 'recyclerview-v7'
    }
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile "com.android.support:appcompat-v7:$ASVersion"
    compile "com.android.support:support-v4:$ASVersion"
    compile "com.android.support:design:$ASVersion"

}

where def ASVersion = '23.1.1'

Maybe you missed something. Mine already working

Hope it help

Post Status

Asked in February 2016
Viewed 3,654 times
Voted 13
Answered 2 times

Search




Leave an answer