从Cucumber Gherkin功能文件生成Java测试存根文件是否可行?

4

不需要读取特性文件,只需编写正确的注释和变量名称,我希望能够"编译"特性文件并自动生成Java测试文件。

有可能吗?您知道有哪些工具可以做到这一点吗?

2个回答

3
如果您运行Cucumber-JVM,它将为每个未定义的步骤生成代码段。您可以将这些剪切并粘贴到您选择的类中。
在IntelliJ中运行时,您可以使用Alt-Return来生成步骤的定义。Eclipse也有相应的插件可供使用,但我最近没有使用过。

谢谢!在IntelliJ Community Edition中无法工作:(但我可以运行测试并查看未定义的步骤。它只显示最后一步,有没有办法看到所有缺失的步骤? - bentzy
抱歉 - 我正在忙着做某事。但你可以尝试从命令提示符中运行以下命令(这应该会打印出所有代码片段):mvn clean test - Seb Rose

0

你可以设置dryRun=true,这样就可以显示所有缺失的步骤。

@RunWith(Cucumber.class)

@CucumberOptions(  monochrome = true,
                         tags = "@tags",
                     features = "src/test/resources/features/",
                       format = { "pretty","html: cucumber-html-reports",
                                  "json: cucumber-html-reports/cucumber.json" },
                        dryRun = true,
                         glue = "glue_code_folder" )

public class RunCucumber_Test {
  //Run this
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接