gpt4 book ai didi

android - 在 gradle 中添加 espresso-contrib 库后,Espresso 测试未运行

转载 作者:行者123 更新时间:2023-11-30 01:34:31 25 4
gpt4 key购买 nike

当我添加

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

在 gradle 中运行 Espresso 测试,我收到以下错误:

 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.

并且测试没有运行。我怀疑是 gradle 问题所以这是我的应用程序 gradle 文件:

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'


}

我需要添加

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

所以我可以使用 RecyclerView 进行测试。

最佳答案

请检查我的依赖项,尤其是 espresso 的依赖项。

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"

其中 def ASVersion = '23.1.1'

也许你错过了什么。我的已经工作了

希望对你有帮助

关于android - 在 gradle 中添加 espresso-contrib 库后,Espresso 测试未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35275299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com