java - 如何将@ClassRule 转换为扩展?
问题描述
我目前正在转换我的 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
我可以扩展,但我找不到这个工件,谢谢!
解决方案
JUnit Jupiter 对JUnit 4 规则的支持有限,但不包括对@ClassRule
.
因此,如果您有为 JUnit 4 编写的自定义类规则,最好的办法是使用 JUnit Jupiter 中的BeforeAllCallback
和AfterAllCallback
扩展 API 重写它。然后,您可以通过或注册您的分机。@ExtendWith
@RegisterExtension
推荐阅读
- javascript - 将对象数组的元素复制到新的对象数组
- azure - 针对 azurite 启动 minio azure 网关
- asp.net - 如果将内容编码添加到标头,则 OutputCache 不起作用
- c++ - 如何从客户端设置 COM 服务器的 dll 搜索路径?
- openssl - 如何重定向到 openssl s_server 标准输入?
- php - 如何检查php中类型为“字符变化”的字段的值是数字还是字符串?
- reactjs - BrowserRouter上组件的条件渲染
- python - python生成器创建从另一个生成器馈送的项目列表
- vb.net - 为什么我的 IComparer 排序出现空引用异常?
- html - Bootstrap 4 响应式重新排序填充空间