黄瓜不适用于 @EnableIf 注释

Cucumber does not work with @EnableIf annotation

我想使用@EnableIf 注释启用黄瓜测试,但即使我添加 @EnabledIf("false")

它也不起作用

这是我使用的代码:

@EnabledIf("false")
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@CucumberContextConfiguration
public class CucumberRoot {

    private int port = 8080;

    protected String DEFAULT_URL = "http://localhost:" + port + "/";

    @Autowired
    protected TestRestTemplate template;
}

除了 Cucumber 之外的其他集成测试,我可以使用 @EnableIf 注释。

有什么方法可以实现吗?

没有

https://junit.org/junit5/docs/current/user-guide/

1.1. What is JUnit 5?

Unlike previous versions of JUnit, JUnit 5 is composed of several different modules from three different sub-projects.

JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage

The JUnit Platform serves as a foundation for launching testing frameworks on the JVM. It also defines the TestEngine API for developing a testing framework that runs on the platform. Furthermore, the platform provides a Console Launcher to launch the platform from the command line and a JUnit 4 based Runner for running any TestEngine on the platform in a JUnit 4 based environment. First-class support for the JUnit Platform also exists in popular IDEs (see IntelliJ IDEA, Eclipse, NetBeans, and Visual Studio Code) and build tools (see Gradle, Maven, and Ant).

JUnit Jupiter is the combination of the new programming model and extension model for writing tests and extensions in JUnit 5. The Jupiter sub-project provides a TestEngine for running Jupiter based tests on the platform.

JUnit Vintage provides a TestEngine for running JUnit 3 and JUnit 4 based tests on the platform.

与 JUnit Jupiter 和 JUnit Vintage 一样,Cucumber 是 JUnit 平台上的测试引擎。您使用的注释是 JUnit Jupiter 注释,只能被 JUnit Jupiter 理解。 JUnit Vintage 和 Cucumber 都看不懂。

但是 Cucumber 确实支持 OpenTest4Js TestAbortedException。因此,您可以使用 before hook 在执行任何步骤之前停止场景。通过直接抛出异常或使用 JUnit Jupiter 中的 Assumptions

    @Before
    public void before() {
        boolean condition = // decide if tests should abort
        if (condition)
            throw new TestAbortedException()
    }

   @Before
   public void before() {
       boolean condition = // decide if tests should abort
       Assumptions.assumeTrue(condition, "Condition not met");
   }