【问题标题】:Espresso Tests cannot access class fileEspresso 测试无法访问类文件
【发布时间】:2018-04-28 08:08:45
【问题描述】:

我在尝试运行 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

【问题讨论】:

  • 我不确定,但尝试在 gradle 中从 espresso 中排除 recyclerview。
  • 我可以注释掉该行,然后该错误不会被抛出,但仍然会抛出其他错误。
  • 你能发布你的毕业作品吗
  • 我刚刚更新以包含指向我的 Gradle 文件的链接

标签: android ui-testing android-espresso


【解决方案1】:

build.gradle 明确排除了生产 apk 的所有依赖项,这反过来又从检测 apk 中排除了兼容库。 我不确定为什么需要这样做,因为我从未遇到过评论中提到的错误。

基本上,删除这个块:

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

会解决的。

【讨论】:

  • 非常感谢您的成功。我要等到我可以为这个问题创建一个赏金并用赏金奖励你,因为我几个月来一直在努力解决这个问题。
  • 我在这里打开了一个问题github.com/googlecodelabs/android-testing/issues/84
  • 嘿,你能解释一下你是如何找出导致问题的脚本块的吗?这个问题也出现在 codelabs 示例中。
  • 非常感谢您找到解决方案。
猜你喜欢
  • 2022-01-12
  • 1970-01-01
  • 1970-01-01
  • 2022-08-02
  • 2023-03-28
  • 2017-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多