我正在使用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
这第一次发生在我在片段测试中添加了这段代码之后:
这些都是我的自由联盟:
我有这些进口品:
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
发布于 2021-07-31 20:08:39
TLDR回答,您不需要降低整个espresso设置的级别-- Hamcrest版本与传递依赖的冲突可以很容易地解决:
如果您正在使用:
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
//change it to:
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0'
如果您正在使用:
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终端中打印出依赖树:
./gradlew :app:dependencies
我们可以在两个版本级别上使用依赖项运行两次,并检查差异。
在几个点上,有一些请求与大多数常见的android dependencies.
不起作用。
[
发布于 2021-04-02 14:33:54
经过一段时间的挣扎之后,我意识到错误是由espresso-contib
和espresso-accessibility
依赖引起的。我的浓缩咖啡是最新的版本3.4.0-alpha 05。
我把它们拿走了,测试也通过了。
先于包括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"
后对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"
发布于 2022-07-06 21:23:24
我没有尝试接受的答案,但有些回复为我节省了一美元,只是补充说:
androidTestImplementation "org.hamcrest:hamcrest:2.2"
https://stackoverflow.com/questions/66915068
复制相似问题