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);

 

posted @ 2022-07-22 00:59  许伟强  阅读(439)  评论(0编辑  收藏  举报