Static Imports

当直接使用 MockMvc 执行请求时,你需要静态导入:

When using MockMvc directly to perform requests, you’ll need static imports for:

  • MockMvcBuilders.*

  • MockMvcRequestBuilders.*

  • MockMvcResultMatchers.*

  • MockMvcResultHandlers.*

记住它的一个简单方法是搜索 MockMvc*。如果使用 Eclipse,请务必在 Eclipse 首选项中将上述内容添加为“最喜欢的静态成员”。

An easy way to remember that is search for MockMvc*. If using Eclipse be sure to also add the above as “favorite static members” in the Eclipse preferences.

当通过WebTestClient使用 MockMvc 时,您不需要静态导入。`WebTestClient`提供了一个没有静态导入的流畅 API。

When using MockMvc through the WebTestClient you do not need static imports. The WebTestClient provides a fluent API without static imports.