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

不羁岁月 提交于 2019-12-24 16:15:02

问题


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.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:54)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:240)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1889)

Tests ran to completion.

and the tests aren't running. I suspect is a gradle problem so here is my app gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    dataBinding {
        enabled = true
    }
    defaultConfig {
        applicationId "databinding.com.masterdetails"
        minSdkVersion 18
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'


    androidTestCompile 'com.android.support:support-annotations:23.1.1'
    // Android JUnit Runner
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    // JUnit4 Rules
    androidTestCompile 'com.android.support.test:rules:0.4.1'
    // Espresso core
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    // Espresso-contrib for DatePicker, RecyclerView, Drawer actions, Accessibility checks, CountingIdlingResource
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-idling-resource:2.2.1'


}

I need to add

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

so I can test with RecyclerView.


回答1:


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




回答2:


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'
}


来源:https://stackoverflow.com/questions/35275299/espresso-test-arent-running-after-adding-espresso-contrib-library-in-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!