AssertJ Integration

AssertJ 集成建立在简单的 MockMvc 之上,有几个不同之处:

The AssertJ integration builds on top of plain MockMvc with several differences:

  • 不必使用静态导入,因为请求和断言均可使用流畅 API 制作。

  • There is no need to use static imports as both the requests and assertions can be crafted using a fluent API.

  • 未解决的异常会得到一致处理,这样,你的测试就不必抛出(或捕获)`Exception`了。

  • Unresolved exceptions are handled consistently so that your tests do not need to throw (or catch) Exception.

  • 默认情况下,要断言的结果是否完整,无论处理是否是异步的。换句话说,无需对 Async 请求进行特殊处理。

  • By default, the result to assert is complete whether the processing is asynchronous or not. In other words, there is no need for special handling for Async requests.

MockMvcTester 是 AssertJ 支持的入口点。它允许构建请求并返回与 AssertJ 兼容的结果,这样就可以将其包装在标准的 assertThat() 方法中。

MockMvcTester is the entry point for the AssertJ support. It allows to craft the request and return a result that is AssertJ compatible so that it can be wrapped in a standard assertThat() method.