首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >测试错误- NoClassDefFoundError:解析度为:Lorg/hamcrest/Matcher

测试错误- NoClassDefFoundError:解析度为:Lorg/hamcrest/Matcher
EN

Stack Overflow用户
提问于 2021-04-02 06:02:07
回答 3查看 2.7K关注 0票数 8

我正在使用Espresso进行仪器化测试,但是在堆栈跟踪中得到了以下错误:

错误是由缺少的类引起的,如下所示:

代码语言:javascript
运行
复制
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

这第一次发生在我在片段测试中添加了这段代码之后:

这些都是我的自由联盟:

我有这些进口品:

代码语言:javascript
运行
复制
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
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2021-07-31 20:08:39

TLDR回答,您不需要降低整个espresso设置的级别-- Hamcrest版本与传递依赖的冲突可以很容易地解决:

如果您正在使用:

代码语言:javascript
运行
复制
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'

//change it to:
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0'

如果您正在使用:

代码语言:javascript
运行
复制
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.4.0'

//change it to:
androidTestImplementation "androidx.test.espresso:espresso-accessibility:3.3.0"

你应该还能把浓缩咖啡的核心保持在更高的3.4.0版本

如果您想要理解,下面是更详细的解释:

要查看引擎盖下面发生了什么,我们可以使用依赖项gradle任务在android studio终端中打印出依赖树:

代码语言:javascript
运行
复制
./gradlew :app:dependencies

我们可以在两个版本级别上使用依赖项运行两次,并检查差异。

在几个点上,有一些请求与大多数常见的android dependencies.

  • On (v3.3.0版本的依赖树)相匹配,即对hamcrest库的请求----每个hamcrest传递依赖项都是按请求提供的,毫不奇怪,它的工作原理是!右侧的

  • (v3.4.0的依赖树)--我们可以看到一些请求在更高的版本中得到了“替代”的hamcrest库,在这种情况下,

不起作用。

[

票数 20
EN

Stack Overflow用户

发布于 2021-04-02 14:33:54

经过一段时间的挣扎之后,我意识到错误是由espresso-contibespresso-accessibility依赖引起的。我的浓缩咖啡是最新的版本3.4.0-alpha 05

我把它们拿走了,测试也通过了。

先于包括espresso-contribespresso-accessibility

代码语言:javascript
运行
复制
/*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"

espresso-contribespresso-accessibility的评论

代码语言:javascript
运行
复制
//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"
票数 5
EN

Stack Overflow用户

发布于 2022-07-06 21:23:24

我没有尝试接受的答案,但有些回复为我节省了一美元,只是补充说:

代码语言:javascript
运行
复制
androidTestImplementation "org.hamcrest:hamcrest:2.2"
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66915068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档