Espresso Tests cannot access class file

2019-04-19 07:39发布

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条回答
我欲成王,谁敢阻挡
2楼-- · 2019-04-19 08:07

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.

查看更多
登录 后发表回答