SecurityMockMvcRequestBuilders

Spring MVC Test 还提供 RequestBuilder 接口,可以通过该接口来创建 MockHttpServletRequest 在您的测试中使用。Spring Security 提供一些 RequestBuilder 实现,可以利用它们使测试变得更轻松。为使用 Spring Security 的 RequestBuilder 实现确保已使用了以下静态导入:

Spring MVC Test also provides a RequestBuilder interface that can be used to create the MockHttpServletRequest used in your test. Spring Security provides a few RequestBuilder implementations that can be used to make testing easier. In order to use Spring Security’s RequestBuilder implementations ensure the following static import is used:

  • Java

  • Kotlin

import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.*;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.*