[英]Cannot resolve symbol when accessing resources from library module in androidTest of application
[英]androidTest not compiling, showing cannot resolve symbol
我正在尝试在我的android项目中使用Espresso添加检测测试。
除了添加AndroidJUnitRunner作为testInstrumentationRunner之外,我还添加了所有必需的库:
但是由于某些原因,导入无法在检测的测试文件中进行:
但是本地测试文件可以正确导入:
我还添加了junit作为androidTestImplementation ,但没有区别:
androidTestImplementation 'junit:junit:4.12'
这就是为什么我无法运行测试文件的原因。
如果仍然运行文件,则会出现此错误:
Process finished with exit code 1
Class not found: "com.mcp.shippax.MainActivityEspressoTest"Empty test suite.
我不理解为什么如此简单的设置会发生这种情况(许多成绩同步/使缓存无效/重新启动)。
除了将大多数源文件(包括测试文件)转换为Kotlin外,我不记得进行任何项目更改。 但是后来,我再次将测试文件恢复为java。
我遇到过同样的问题。 我在开发人员和产品环境中使用了各种构建类型,而对我有所帮助的是像在此答案中那样指定testBuildType https://stackoverflow.com/a/34778780/9736105 。
所以像这样:
android {
...
testBuildType "<my-build-type>"
buildTypes {
<my-build-type> {
...
}
....
}
}
完成该操作并将构建变体设置为该构建类型之后,我便能够解决所有依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.