什么时候用@IncludeEngines,什么时候用Junit5的@ExtendWith
When to use @IncludeEngines and when to use@ExtendWith of Junit5
请支持我理解和克服何时使用的困惑
@IncludeEngines
以及何时在 JUnit 5 中使用 @ExtendWith
。
抱歉,如果这个问题太基础了。
提前致谢。
@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
请支持我理解和克服何时使用的困惑
@IncludeEngines
以及何时在 JUnit 5 中使用 @ExtendWith
。
抱歉,如果这个问题太基础了。
提前致谢。
@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
.