【发布时间】:2022-01-13 21:32:03
【问题描述】:
我正在尝试使用 Cucumber 的 CLI Runner 并行运行 Cucumber 的功能文件,我目前正试图弄清楚如何使 JUnit @BeforeClass 挂钩与 CLI Runner 一起工作。
目前,我的 工作 Runner 类如下所示:
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {
"pretty",
"html:target/reports/basic/report.html",
"json:target/reports/cluecumber/cucumber.json",
"timeline:target/reports/timeline"
},
tags = "@RegressionTests",
snippets = SnippetType.CAMELCASE,
stepNotifications = true,
features = "classpath:features",
glue = "my.steps.package")
public class RegressionTestsIT {
@BeforeClass
public static void setup() {
ContextHolder.setupTestContext();
}
}
我的 CLI 命令如下所示:
java -cp "target/test-jar-with-dependencies.jar" io.cucumber.core.cli.Main -p "pretty" -p "html:target/reports/basic/report.html" -p "json:target/reports/cluecumber/cucumber.json" -p "timeline:target/reports/timeline" --threads 10 -g "my.steps.package" target/test-classes/features
发生的情况是我在测试中收到 NullPointerException,因为未正确设置 TestContext,因为未执行钩子。
我尝试将 Runner 的包和 Runner 类本身作为胶水包含在内,但它不起作用。
还尝试让我的 Runner 扩展 io.cucumber.core.cli.Main 然后在 CLI 中执行我的 Runner,毫不奇怪它也没有工作,遗憾的是仍然得到 NPE。
虽然这个问题与 CLI Runner 的使用有关,但我对任何可能帮助我并行运行多个功能文件的答案感到满意。
【问题讨论】:
-
你能把
--threads 10改成-threads 10试试看。请查看它可能会有所帮助ghchirp.tech/283 -
您确定在 test-jar-with-dependencies.jar 中有 JUnit 吗?
-
谢谢大家,找到适合我的解决方案。
-
@AlexeyR,是的,JUnit 被捆绑在了 jar 中。
-
(也许 Cucumber CLI Runner 根本不使用 cucumber-junit?)
标签: java junit cucumber integration-testing cucumber-java