Fan*_*dez 11 dependencies android gradle android-testing android-espresso
我正在使用 Espresso 进行仪器测试,但在堆栈跟踪上出现此错误:

该错误是由于缺少类引起的,如下所示:
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.hamcrest.Matchers" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/system/framework/android.test.base.jar", zip file "/data/app/~~vnZzxGNKnS4V6YkEf4falA==/com.example.android.architecture.blueprints.reactive.test-K_x0_yJ0hJeDHaJkDmHXRw==/base.apk", zip file "/data/app/~~oeYx2MgTcILbk-vq_WPx1A==/com.example.android.architecture.blueprints.reactive-0wMHYEe95hx_1cnbdAoZAw==/base.apk"],nativeLibraryDirectories
Run Code Online (Sandbox Code Playgroud)
它首先发生在我在片段测试中添加此代码后:

这些是我在 Gradle 上的相关库:

我有这些进口:
import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.hamcrest.core.IsNot.not
Run Code Online (Sandbox Code Playgroud)
Hen*_*eMS 27
TLDR 答案,您不需要降级整个 espresso 设置,因为 Hamcrest 版本与传递依赖项存在冲突,可以轻松解决:
如果您正在使用:
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
//change it to:
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0'
Run Code Online (Sandbox Code Playgroud)
如果您正在使用:
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.4.0'
//change it to:
androidTestImplementation "androidx.test.espresso:espresso-accessibility:3.3.0"
Run Code Online (Sandbox Code Playgroud)
您应该仍然能够将 espresso 核心保留在更高的 3.4.0 版本
如果你想理解,这里有更长的解释:
要查看幕后发生的情况,我们可以使用依赖项 gradle 任务在 android studio 终端中打印出依赖关系树:
./gradlew :app:dependencies
Run Code Online (Sandbox Code Playgroud)
我们可以使用两个版本级别的依赖关系运行它两次,并可以检查差异。
[
小智 14
我没有尝试接受的答案,但有些回复保存了我的a$$,只需添加:
androidTestImplementation "org.hamcrest:hamcrest:2.2"
Run Code Online (Sandbox Code Playgroud)
经过一段时间的挣扎,我意识到错误是由espresso-contib和espresso-accessibility依赖性引起的。我的浓缩咖啡版本是最新版本 3.4.0-alpha05。
我删除了它们并且测试通过了。
在包含espresso-contrib&之前espresso-accessibility
/*core contains matches and view assertions, included by default on android project*/
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
//testing code for advanced views such as recyclerview and Date picker
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
androidTestImplementation "androidx.test.espresso.idling:idling-concurrent:$espressoVersion"
Run Code Online (Sandbox Code Playgroud)
注释掉espresso-contrib&后espresso-accessibility
//core contains matches and view assertions, included by default on android project
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
//testing code for advanced views such as recyclerview and Date picker
//androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
//androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
androidTestImplementation "androidx.test.espresso.idling:idling-concurrent:$espressoVersion"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5318 次 |
| 最近记录: |