无法从Espresso Test Recorder

时间:2016-10-18 22:03:30

标签: android android-espresso

我使用测试记录器创建一个简单的UI测试。但是,当我运行生成的测试时,我收到错误

Error:(4, 37) error: package android.support.test.espresso does not exist
Error:(5, 33) error: package android.support.test.rule does not exist
Error:(6, 35) error: package android.support.test.runner does not exist
Error:(14, 20) error: package org.hamcrest does not exist
Error:(15, 20) error: package org.hamcrest does not exist
Error:(16, 20) error: package org.hamcrest does not exist
Error:(17, 25) error: package org.hamcrest.core does not exist
Error:(18, 17) error: package org.junit does not exist
Error:(19, 17) error: package org.junit does not exist
Error:(20, 24) error: package org.junit.runner does not exist
Error:(22, 44) error: package android.support.test.espresso does not exist
Error:(22, 1) error: static import only from classes and interfaces
Error:(23, 51) error: package android.support.test.espresso.action does not exist
Error:(23, 1) error: static import only from classes and interfaces

你明白了。在尝试运行测试之前,我在Android Studio中没有看到任何警告或错误。

有没有人知道可能是什么问题?

2 个答案:

答案 0 :(得分:0)

您是否添加了忘记添加espresso到您的依赖项?

androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'

答案 1 :(得分:0)

经过进一步检查,此处发现类似问题: https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened&groupby=&sort=&id=98326

他们的解决方案对我不起作用。事实证明我要从build.gradle中的java sourceset中排除测试包。

sourceSets{
  main {
    java.srcDirs = ['src']
    java.excludes = ['instrumentTest/**','test/**']
    ...
  }
}