[英]How to run tests filtered with tags with cucumber-jvm and gradle?
I work with cucumber for some time now, and now I want to migrate test suite usage to gradle from maven. 我现在使用黄瓜已经有一段时间了,现在我想将测试套件的使用情况从maven迁移到gradle。
I managed to prepare the project covering the basic usage, running tests, having the results etc. The last piece I am missing is ability to only run the tests filtered on specific tag. 我设法准备项目,包括基本用法,运行测试,结果等。我遗漏的最后一块是只能运行在特定标签上过滤的测试。 Running acceptance tests is done with product flavor:
运行验收测试是通过产品风格完成的:
productFlavors {
uats {
testInstrumentationRunner "com.paddy.cuespton.cuespton.test.Instrumentation"
}
full {
applicationId "com.paddy.app.cuespton"
versionName "1.0"
}
}
Which enables me to run tests with task: 这使我能够使用任务运行测试:
./gradlew connectedAndroidTestUatsDebug
Is is possible to add param with tag to this task to run specific tests only? 是否可以将param with tag添加到此任务以仅运行特定测试?
I tried to use https://github.com/samueltbrown/gradle-cucumber-plugin/ plugin which should in theory solve this issue, but I cannot get it running with Android due to language incompatibility. 我尝试使用https://github.com/samueltbrown/gradle-cucumber-plugin/插件,理论上应解决此问题,但由于语言不兼容,我无法使用Android运行。
Here is repo on which I am working, https://github.com/paddyzab/espresso-cucumber-sandbox . 这是我工作的回购, https://github.com/paddyzab/espresso-cucumber-sandbox 。
Thanks for help! 感谢帮助!
Didn't try this cucumber-plugin but assuming that we have similar setup you can do the following ( sample repo ): 没有尝试这个黄瓜插件,但假设我们有类似的设置,你可以做以下( 样本回购 ):
1) define corresponding buildConfigField for the uats flavor: 1)为uats风格定义相应的buildConfigField:
Uats {
testInstrumentationRunner "com.quandoo.gradletestpoc.test.Instrumentation"
// passing instrumentation parameters
buildConfigField "String", "TAGS", "\"${getTagsProperty()}\""
}
2) define getTagsProperty() method: 2)定义getTagsProperty()方法:
def getTagsProperty() {
return project.hasProperty("tags") ? project.getProperties().get("tags") : ""
}
3) Handle passed tag in onCreate() method of your custom instrumentation class: 3)处理自定义检测类的onCreate()方法中的传递标记:
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) Run 4)跑
./gradlew connectedAndroidTestUatsDebug -Ptags="@bar"
Enjoy! 请享用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.