仅对当前构建类型进行 Robolectric 运行 测试

Make Robolectric run test for the current build type only

我正在使用 Robolectric 和 Android Studio (v 1.2.2)

classpath 'com.android.tools.build:gradle:1.2.3'

buildToolsVersion "21.1.2"

testCompile 'org.robolectric:robolectric:3.0-rc3'

我的项目包含 4 种构建类型。尽管在“构建变体”window 中选择了 debug 构建类型,Robolectric 测试了每个声明的构建类型(4 次)。

这是预期的行为吗?如何将执行范围缩小到 debug 构建类型?

谢谢。

很简单。假设您有下一个:

productFlavours {
   one
   two
}

所以要 运行 测试味道,你只需 运行 gradle:

gradle testOneDebug

到运行所有变体的所有测试:

gradle test