【发布时间】:2014-03-06 12:44:28
【问题描述】:
我在 groovy 代码中使用 cucumber-java。我更喜欢 cucumber-java 而不是 cucumber-groovy,因为我可以像普通的老式 JUnit 测试一样运行测试。但是cucumber吐出来的步骤定义模板是java风格的。相反,我想要一种时髦的风格。例如,在 java 风格中,你会得到类似的东西
@When("^an HTTP GET request is sent to obtain config.xml of \"([^\"]*)\"$")
public void an_HTTP_GET_request_is_sent_to_obtain_config_xml_of(String arg1) throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
由于我使用的是 groovy,所以我想获得类似的东西
@When(/^an HTTP GET request is sent to obtain config.xml of "([^"]*)"$/)
void 'an HTTP GET request is sent to obtain config.xml of'(String arg1) {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
我正在考虑实现这样的功能。基本上,我的想法是在cucumber.api.CucumberOptions 中添加一个新字段,可能称为templateLanguage。当这个新字段等于groovy 时,groovy 样式的模板将被吐出。这可能会涉及到cucumber.runtime.java.JavaSnippet.template() 中的if 语句,例如if( runtimeOptions.getTemplateLanguage().toLowerCase().equals('groovy') ) {...}
但是,我的问题是:如何获取传入的 runtimeOptions 的引用,如
@CucumberOptions(
format = ["pretty", "html:build/cucumber"],
features="src/test/resources/cucumber_features/api/job_view.feature",
glue=['com.yahoo.adcd.jenkins.tests.smoke.api.cucumber.job.view'],
strict = true
)
非常感谢!
【问题讨论】:
-
你检查
RuntimeOptions.javagithub.com/cucumber/cucumber-jvm/blob/master/core/src/main/java/… -
是的,我做到了。但是没有找到任何有用的东西?有什么想法吗?
-
你有办法解决这个问题吗?
-
如果你想给 Cucumber-groovy 添加一个特性,也许你应该看看 Github 上的项目:github.com/cucumber/cucumber-jvm-groovy。有关如何实现此功能的问题,最好联系 Slack 上的开发人员:cucumber.io/support#slack
标签: java groovy junit cucumber cucumber-jvm