springboot单元测试常用写法
1. 启动类
2. 测试类
@RunWith(SpringRunner.class) @SpringBootTest(classes = { ReportSplTestApp.class }) @AutoConfigureMockMvc @Test
模拟发送请求
@Autowired
MockMvc
String j = "{}"; MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post("/list/get"); request.content(j); MvcResult r = mockMvc.perform(request).andReturn(); String s = r.getResponse().getContentAsString(); System.out.println(s);
I can see a bigger world.