Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso Tests cannot access class file

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

like image 476
Etienne Lawlor Avatar asked Nov 15 '17 07:11

Etienne Lawlor


1 Answers

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.

like image 73
Be_Negative Avatar answered Sep 19 '22 05:09

Be_Negative