【问题标题】:Cucumber does not work with @EnableIf annotationCucumber 不适用于 @EnableIf 注释
【发布时间】:2021-11-06 05:25:16
【问题描述】:

我想启用带有@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;
}

对于黄瓜以外的其他集成测试,我可以使用@EnableIf 注释。

有什么方法可以实现吗?

【问题讨论】:

    标签: spring-boot cucumber enable-if


    【解决方案1】:

    没有。

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

    1.1。什么是 JUnit 5?

    与以前的 JUnit 版本不同,JUnit 5 由来自三个不同子项目的几个不同模块组成。

    JUnit 5 = JUnit 平台 + JUnit Jupiter + JUnit Vintage

    JUnit 平台是在 JVM 上启动测试框架的基础。它还定义了用于开发在平台上运行的测试框架的 TestEngine API。此外,该平台还提供了一个控制台启动器,用于从命令行启动平台,以及一个基于 JUnit 4 的 Runner,用于在基于 JUnit 4 的环境中运行平台上的任何 TestEngine。流行的 IDE(参见 IntelliJ IDEA、Eclipse、NetBeans 和 Visual Studio Code)和构建工具(参见 Gradle、Maven 和 Ant)中也存在对 JUnit 平台的一流支持。

    JUnit Jupiter 是用于在 JUnit 5 中编写测试和扩展的新编程模型和扩展模型的组合。Jupiter 子项目提供了一个 TestEngine,用于在平台上运行基于 Jupiter 的测试。

    JUnit Vintage 提供了一个测试引擎,用于在平台上运行基于 JUnit 3 和 JUnit 4 的测试。

    与 JUnit Jupiter 和 JUnit Vintage 一样,Cucumber 是 JUnit 平台上的测试引擎。您使用的注解是 JUnit Jupiter 注解,只有 JUnit Jupiter 才能理解。 JUnit Vintage 和 Cucumber 都无法理解。

    但是 Cucumber 确实支持 OpenTest4Js TestAbortedException。因此,您可以使用 before 挂钩在执行任何步骤之前停止场景。通过直接抛出异常或使用来自 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");
       }
    

    【讨论】:

      猜你喜欢
      • 2021-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-15
      • 2014-08-31
      • 2016-05-01
      相关资源
      最近更新 更多