【问题标题】:How do I convert @ClassRule into an Extention?如何将@ClassRule 转换为扩展?
【发布时间】:2021-02-03 19:48:02
【问题描述】:

我目前正在转换我的 WebFlux 应用程序以使用 v4 的 junit 5,我的 gradle.properties 有

testImplementation ("org.springframework.boot:spring-boot-starter-test") {
exclude group : 'org.junit.vintage', module: 'junit-vintage-engine'
}

以及独立的wiremock依赖

testImplementation "org.springframework.cloud:spring-cloud-contract-wiremock:${springCloudVersion}"

我正在尝试找出一种在 junit 5 中加载 classRule 或将其转换为扩展的方法,这似乎是最减少代码的方法。

有人遇到过这些问题并解决了吗?我知道有 WireMockExtention.class 我可以扩展,但我找不到这个工件,谢谢!

【问题讨论】:

    标签: java spring-webflux junit5 wiremock


    【解决方案1】:

    JUnit Jupiter 对JUnit 4 Rules 的支持有限,但这不包括对@ClassRule 的支持。

    因此,如果您有为 JUnit 4 编写的自定义类规则,最好的办法是使用 JUnit Jupiter 中的 BeforeAllCallbackAfterAllCallback 扩展 API 重写它。然后您可以通过@ExtendWith@RegisterExtensionregister your extension

    【讨论】:

      猜你喜欢
      • 2010-10-14
      • 1970-01-01
      • 2022-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-20
      • 1970-01-01
      • 2019-06-28
      相关资源
      最近更新 更多