我知道我们可以通过在build.gradle文件中指定以下内容来将黄瓜标签传递给Gradle:
test {
systemProperty "cucumber.options", System.getProperty("cucumber.options")
}
因此,当您运行gradlew test -Dcucumber.options="--tags @CDC"
时,它将仅运行带有CDC标签的方案。
但是我的问题是我是否可以将黄瓜选项传递给黄瓜任务。我需要执行此操作的原因是因为我的黄瓜任务在运行任务后创建了一个JSON文件,并且我正在使用gradle-cucumber-reporting插件(https://github.com/SpacialCircumstances/gradle-cucumber-reporting)来基于JSON文件生成报告。
黄瓜任务
task cucumber() {
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = [
'--plugin', 'html:cucumber-report',
'--plugin', 'json:cucumber.json', //generates a .json report file
'--plugin', 'pretty',
'--plugin', 'usage:cucumber-usage.json',
'--glue', 'hellocucumber', 'src/test/resources']
}
}
}
在Gradle中运行test
任务不会更新JSON文件。
这是gradle-cucumber-reporting的摘录:
cucumberReports {
outputDir = file('cucumber-pretty-report')
buildId = '0'
reports = files('cucumber.json')
}
您可以在黄瓜任务中添加这样的内容:
def tags = getProperty("tags")
args = [
'--plugin', 'html:cucumber-report',
'--plugin', 'json:cucumber.json', //generates a .json report file
'--plugin', 'pretty',
'--plugin', 'usage:cucumber-usage.json',
'--glue', 'hellocucumber', 'src/test/resources'
'--tags', tags]
比您可以通过这种方式运行任务:
gradle cucumber -P tags=smoke