Espresso和BuildVariants

时间:2015-05-05 08:33:51

标签: android android-testing android-espresso

我们有三个BuildVariants:releasedebugdevelop。第一个是AndroidStudio的默认值。最后一个是我们的内部测试。以下是配置:(没有什么不同于Signing Configenter image description here enter image description here

我们在build.gradle

中导入以下内容
dependencies {
    // App dependencies
    compile 'com.android.support:support-annotations:22.0.0'
    compile 'com.google.guava:guava:18.0'
    // Testing-only dependencies
    androidTestCompile 'com.android.support.test:runner:0.2'
    androidTestCompile 'com.android.support.test:rules:0.2'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
}

现在我们已经创建了androidTest/文件夹(Espresso-Tests所在的位置)。我查看了Android-Testing Samples in GitHub.

中的示例

但是AndoridStudio总是为AndroidJUnit4.class说“找不到Symbole”: enter image description here

(现在,经过大量解释 - 抱歉:D) 我发现了这个问题。我们的构建变体设置在Android Instrumented Tests(这没关系),但应用模块位于develop BuildVariant。当我们将其更改为debug时,一切都很好。

现在我不确定这是一个错误还是这是正常的?!因为我们没有什么不同 - 而不是Singing Config(但我测试过它,这不是问题) - 在BuildVariants上。当它正常时,为什么?!

修改

我也创建了一张AOSP-Ticket:https://code.google.com/p/android/issues/detail?id=172029

1 个答案:

答案 0 :(得分:2)

请参阅我对该错误的更新。简而言之,您需要这一行:

android {
  testBuildType "develop"
}