如何运行用 cucumber-jvm 和 gradle 标签过滤的测试?
How to run tests filtered with tags with cucumber-jvm and gradle?
我使用 Cucumber 已经有一段时间了,现在我想将测试套件的使用从 maven 迁移到 gradle。
我设法准备了涵盖基本用法、运行测试、获得结果等的项目。
我缺少的最后一块是只能运行在特定标签上过滤的测试的能力。
运行验收测试是用产品风味完成的:
productFlavors {
uats {
testInstrumentationRunner "com.paddy.cuespton.cuespton.test.Instrumentation"
}
full {
applicationId "com.paddy.app.cuespton"
versionName "1.0"
}
}
这使我能够使用任务运行测试:
./gradlew connectedAndroidTestUatsDebug
是否可以将带有标签的参数添加到此任务以仅运行特定测试?
我试过用
https://github.com/samueltbrown/gradle-cucumber-plugin/ 理论上应该可以解决这个问题的插件,但由于语言不兼容,我无法使用 Android 运行它。
这是我正在处理的回购协议,
https://github.com/paddyzab/espresso-cucumber-sandbox.
感谢帮助!
没有尝试过这个 cucumber-plugin,但假设我们有类似的设置,您可以执行以下操作 (sample repo):
1) 为uats flavor定义相应的buildConfigField:
Uats {
testInstrumentationRunner "com.quandoo.gradletestpoc.test.Instrumentation"
// passing instrumentation parameters
buildConfigField "String", "TAGS", "\"${getTagsProperty()}\""
}
2) 定义 getTagsProperty() 方法:
def getTagsProperty() {
return project.hasProperty("tags") ? project.getProperties().get("tags") : ""
}
3) 在您的自定义检测的 onCreate() 方法中处理传递的标签 class:
private static final String TAGS_KEY = "tags";
......
@Override
public void onCreate(final Bundle bundle) {
super.onCreate(bundle);
// Reading runner params
String tags = BuildConfig.TAGS;
if (!tags.isEmpty()) {
bundle.putString(TAGS_KEY, tags);
}
instrumentationCore.create(bundle);
start();
}
4) 运行
./gradlew connectedAndroidTestUatsDebug -Ptags="@bar"
尽情享受吧!
我使用 Cucumber 已经有一段时间了,现在我想将测试套件的使用从 maven 迁移到 gradle。
我设法准备了涵盖基本用法、运行测试、获得结果等的项目。 我缺少的最后一块是只能运行在特定标签上过滤的测试的能力。 运行验收测试是用产品风味完成的:
productFlavors {
uats {
testInstrumentationRunner "com.paddy.cuespton.cuespton.test.Instrumentation"
}
full {
applicationId "com.paddy.app.cuespton"
versionName "1.0"
}
}
这使我能够使用任务运行测试:
./gradlew connectedAndroidTestUatsDebug
是否可以将带有标签的参数添加到此任务以仅运行特定测试?
我试过用 https://github.com/samueltbrown/gradle-cucumber-plugin/ 理论上应该可以解决这个问题的插件,但由于语言不兼容,我无法使用 Android 运行它。
这是我正在处理的回购协议, https://github.com/paddyzab/espresso-cucumber-sandbox.
感谢帮助!
没有尝试过这个 cucumber-plugin,但假设我们有类似的设置,您可以执行以下操作 (sample repo):
1) 为uats flavor定义相应的buildConfigField:
Uats {
testInstrumentationRunner "com.quandoo.gradletestpoc.test.Instrumentation"
// passing instrumentation parameters
buildConfigField "String", "TAGS", "\"${getTagsProperty()}\""
}
2) 定义 getTagsProperty() 方法:
def getTagsProperty() {
return project.hasProperty("tags") ? project.getProperties().get("tags") : ""
}
3) 在您的自定义检测的 onCreate() 方法中处理传递的标签 class:
private static final String TAGS_KEY = "tags";
......
@Override
public void onCreate(final Bundle bundle) {
super.onCreate(bundle);
// Reading runner params
String tags = BuildConfig.TAGS;
if (!tags.isEmpty()) {
bundle.putString(TAGS_KEY, tags);
}
instrumentationCore.create(bundle);
start();
}
4) 运行
./gradlew connectedAndroidTestUatsDebug -Ptags="@bar"
尽情享受吧!