Espresso Tests cannot access class file

北战南征 提交于 2019-12-22 01:53:26

问题


I get the following errors where i try to run a ui test.

/Users/etiennelawlor/workspace/MovieHub/app/src/androidTest/java/com/etiennelawlor/moviehub/MoviesFragmentTest.java 

Error:(34, 28) error: cannot access AppCompatActivity class file for android.support.v7.app.AppCompatActivity not found 

Error:(34, 58) error: cannot infer type arguments for ActivityTestRule<> 

Error:(41, 41) error: cannot access IdlingResource class file for android.support.test.espresso.IdlingResource not found 

Error:(51, 40) error: cannot access RecyclerView class file for android.support.v7.widget.RecyclerView not found 

Error:Execution failed for task ‘:app:compileDebugAndroidTestJavaWithJavac’.
Compilation failed; see the compiler error output for details.

Here is my Test class : https://github.com/lawloretienne/MovieHub/blob/226492727e4d467b337ed4b689edb05eec0368c2/app/src/androidTest/java/com/etiennelawlor/moviehub/MoviesFragmentTest.java

Am I missing something?

Here is my Gradle file

https://github.com/lawloretienne/MovieHub/blob/master/app/build.gradle


回答1:


The build.gradle explicitly excludes all dependencies of the production apk, which in turn, excludes the compat library from the instrumentation apk. I am not sure why this is required because I have never experienced that bug mentioned in the comment.

Basically, removing this block:

configurations.implementation.dependencies.all { implementationDependency ->
    println "Excluding implementation dependency: ${implementationDependency.getName()}"
    configurations.androidTestImplementation.dependencies.all { androidTestImplementationDependency ->
        configurations.androidTestImplementation.exclude module: "${implementationDependency.getName()}"
    }
}

will fix it.



来源:https://stackoverflow.com/questions/47301670/espresso-tests-cannot-access-class-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!