【SpringBoot】单元测试之测试Service方法
测试Service方法
@SpringBootTest
public class UserServiceTest{
@Autowired
private UserService userService;
@Test
public void findOne () throws Exception{
Assert.assertEquals("1002",userService.findOne());
}
}
测试Controller接口方法
@Runwith(SpringRunner.class)
@WebMvcTest(HelloController.class)
class HelloControllerTest{
@Autowired
private MockMvc mockMvc;
@Test
public void hello() throws Exception{
mockMvc.perform(MockMvcRequestBuilders.post("/hello").contentType(MediaType.APPLICATION_JSON)
.andExpect(status ().isOk())
.andDo(print ());
}
}
原文地址:https://blog.csdn.net/wenhuakulv2008/article/details/140561414
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!