【问题标题】:When to use @IncludeEngines and when to use@ExtendWith of Junit5什么时候使用@IncludeEngines,什么时候使用Junit5的@ExtendWith
【发布时间】:2018-01-31 03:27:57
【问题描述】:

请支持我理解和克服何时使用的困惑 @IncludeEngines 以及何时在 JUnit 5 中使用 @ExtendWith。

抱歉,如果这个问题太简单了。

提前谢谢你。

【问题讨论】:

    标签: unit-testing spring-boot build.gradle junit5 spring-boot-test


    【解决方案1】:

    @ExtendWith用于注册自定义extensions

    就 JUnit4 构造而言:@RunWith、@Rule 和 @ClassRule 都已被 @ExtendWith 取代。尽管 JUnit 5 确实保留了 limited support for rules,但 JUnit 团队的强烈建议是转而使用 @ExtendWith。

    有一些常见的 JUnit4 规则重新实现为 JUnit5 扩展 here 的示例。

    @IncludeEngines 指定在 JUnit 平台上运行测试套件时要包含的 org.junit.platform.engine.TestEngine 实现。尽管这是在org.junit.platform.suite.api 中,因此可供开发人员使用,但我想不出任何需要使用它的情况。它可用于接合特定的引擎,例如老式引擎而不是 JupiterTestEngine,但这意味着需要在 JUnit4 环境中运行测试,这可以使用 @RunWith(JUnitPlatform.class) 来实现。

    你认为你需要使用@IncludeEngines吗?如果是这样,我建议解释一下您认为需要使用它的原因,并且您可能会发现还有其他不需要使用 @IncludeEngines 的 JUnit5 使用方式。

    【讨论】:

    • 就像glytching说的,我们有时需要使用@IncludeEngines来执行像黄瓜引擎这样的引擎的测试
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-04
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    相关资源
    最近更新 更多