Espresso Tests无法访问类文件

时间:2017-11-15 07:28:30

标签: android ui-testing android-espresso

我在尝试运行ui测试时遇到以下错误。

/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.

这是我的测试课:https://github.com/lawloretienne/MovieHub/blob/226492727e4d467b337ed4b689edb05eec0368c2/app/src/androidTest/java/com/etiennelawlor/moviehub/MoviesFragmentTest.java

我错过了什么吗?

这是我的Gradle文件

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

1 个答案:

答案 0 :(得分:14)

build.gradle明确排除了生产apk的所有依赖关系,而后者又从检测apk中排除了compat库。 我不确定为什么这是必需的,因为我从未经历过评论中提到的那个bug。

基本上,删除此块:

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

会解决它。