我使用测试记录器创建一个简单的UI测试。但是,当我运行生成的测试时,我收到错误
Error:(4, 37) error: package android.support.test.espresso does not exist
Error:(5, 33) error: package android.support.test.rule does not exist
Error:(6, 35) error: package android.support.test.runner does not exist
Error:(14, 20) error: package org.hamcrest does not exist
Error:(15, 20) error: package org.hamcrest does not exist
Error:(16, 20) error: package org.hamcrest does not exist
Error:(17, 25) error: package org.hamcrest.core does not exist
Error:(18, 17) error: package org.junit does not exist
Error:(19, 17) error: package org.junit does not exist
Error:(20, 24) error: package org.junit.runner does not exist
Error:(22, 44) error: package android.support.test.espresso does not exist
Error:(22, 1) error: static import only from classes and interfaces
Error:(23, 51) error: package android.support.test.espresso.action does not exist
Error:(23, 1) error: static import only from classes and interfaces
你明白了。在尝试运行测试之前,我在Android Studio中没有看到任何警告或错误。
有没有人知道可能是什么问题?
答案 0 :(得分:0)
您是否添加了忘记添加espresso到您的依赖项?
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
答案 1 :(得分:0)
他们的解决方案对我不起作用。事实证明我要从build.gradle中的java sourceset中排除测试包。
sourceSets{
main {
java.srcDirs = ['src']
java.excludes = ['instrumentTest/**','test/**']
...
}
}