如何在 Cucumber 测试套件中订购功能文件?

How to order feature files in Cucumber test suite?

目前,我发现 Cucumber 测试套件按字母顺序运行功能文件。

如果有任何 option/configuration 我可能遗漏了,请告诉我。谢谢。

您可以强制 Cucumber 按照您将文件名作为参数传递的顺序 运行 功能文件。例如,

$ cucumber file3.feature file2.feature file1.feature

将运行文件按file3.featurefile2.featurefile1.feature.

的顺序排列

您还可以创建一个文本文件,其中包含按所需顺序排列的功能文件名称,每个名称各占一行。例如,假设文件名为 feature_order.txt 并且包含以下内容:

file3.feature
file2.feature
file1.feature

然后您可以运行以下命令运行以上顺序的文件:

$ cucumber $(cat feature_order.txt)

Cucumber features/scenarios 运行 按功能文件名的字母顺序排列。

但是,如果您特别指定功能,则它们应按声明的顺序 运行。例如:

@Cucumber.Options(features={"automatedTestingServices.feature", "smoketest.feature"})

在 cucumber 4.2.0 中添加了 cli 选项 --order,参见 changelog and this example

但是,如果您特别指定功能,则它们应按声明的顺序 运行。例如:

@Cucumber.Options(features={"automatedTestingServices.feature", "smoketest.feature"})

以上仍按字母顺序排列。所以它不会有任何区别

如果您将 Junit 5 与 Cucumber 一起使用,您可以像这样订购功能文件。

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("this/is/number/one.feature")
@SelectClasspathResource("this/is/number/two.feature")
@SelectClasspathResource("this/is/number/three.feature")
public class RunCucumberTest {
}