使用 @Suite Junit 时,CucumberOptions 标记将被忽略

Luc*_*mer 2 java cucumber cucumber-junit spring-boot

@Suite
@SuiteDisplayName("NAME")
@IncludeEngines("cucumber")
@SelectClasspathResource("cucumber/tests")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "cucumber.tests")
@CucumberOptions(tags = "not @IGNORE")
public class RunCucumberTests {}
Run Code Online (Sandbox Code Playgroud)

这是我之前的配置,其中标签不起作用

@IncludeEngines("cucumber")
@SelectClasspathResource("cucumber/tests")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "cucumber.tests")
@CucumberOptions(tags = "not @IGNORE")
@RunWith(Cucumber.class)
public class RunCucumberTests {}
Run Code Online (Sandbox Code Playgroud)

更改此配置后,它就可以工作了。有谁知道为什么?我如何将 suite 和 CucumberOptions 一起使用。

mpk*_*nje 7

您不能@CucumberOptions与 结合使用@Suite。前者用于JUnit 4,后者用于JUnit 5。

@Suite注释启动 JUnit 5 声明性测试套件。这意味着您必须使用 JUnit 5 概念选择要执行的测试。

要使用 JUnit 5 套件定位特定标签,您必须使用@IncludeTags@ExcludeTags注释。例如:

package io.cucumber.skeleton;

import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.ExcludeTags;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("io/cucumber/skeleton")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "io.cucumber.skeleton")
@ExcludeTags("IGNORE")
public class RunCucumberTest {
}
Run Code Online (Sandbox Code Playgroud)

请注意,这些是 JUnit 5 标签,不包括@Cucumber 标签所包含的符号。