junit - Spring REST 文档 : How to migrate Rule to JUnit 5

标签 junit junit4 junit5 spring-restdocs junit-jupiter

我将 Spring 测试迁移到 JUnit 5,它们运行良好。但是,我不知道如何迁移 @Rule public JUnitRestDocumentation restDocumentation = ... .
任何提示表示赞赏。

最佳答案

Spring RestDocs 2 引入了一个新类:RestDocumentationExtension对于 JUnit 5。您可以使用它代替 Rule @ExtendWith(RestDocumentationExtension.class) public class JUnit5ExampleTests {

  • 完整示例可在 https://github.com/spring-projects/spring-restdocs/blob/v2.0.0.RELEASE/samples/junit5/src/test/java/com/example/junit5/SampleJUnit5ApplicationTests.java 上找到
  • 扩展记录在 https://github.com/spring-projects/spring-restdocs/blob/master/docs/src/docs/asciidoc/getting-started.adoc#setting-up-your-junit-5-tests

  • Spring RestDocs 2 需要 Spring 5 和 JDK 8

    关于junit - Spring REST 文档 : How to migrate Rule to JUnit 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39256064/

    相关文章:

    Android RxJava 2 JUnit 测试 - android.os.Looper 中的 getMainLooper 未模拟 RuntimeException

    java - 忽略测试用例中的断言失败 (JUnit)

    java - 为集合的并发访问编写UT

    java - org.hamcrest.Matchers.hasProperty 无法解析

    java - Mockito 不起作用 MockitoSessionLogger DefFoundError

    java - 带有注释为 `@RegisterExtension` 的字段的 JUnit 5 测试在 Kotlin 中不起作用

    java - Maven 找不到要运行的 JUnit 测试

    java - 如何模拟 getApplicationContext

    java - JUnit : Run via eclipse and maven test. 速度差别很大,为什么?

    java - 使用 @ActivateProfiles 在 JUnit5 测试中加载不正确的 SpringBoot 属性文件