我有一个使用Spring Boot 2编写的REST服务,我需要为单元测试禁用安全性。
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
@EnableAutoConfiguration
public class TestController {
@Autowired
private MockMvc mockMvc;
@Autowired
private ObjectMapper mapper;
@Test
public void testHome() {
mockMvc.perform(
post(contentPath)
.contentType(MediaType.APPLICATION_JSON)
.param("testParam", "val1")
.content(mapper.writeValueAsString(data))
).andExpect(status().isOk());
}
}
我该怎么办?