(四)SpringBoot的单元测试与MockMvc

单元测试

1、pom引入相关依赖

       

            org.springframework.boot

            spring-boot-starter-test

            test

       

2.运用 与Testng一样

@RunWith(SpringRunner.class) //底层用junit SpringJUnit4ClassRunner

@SpringBootTest(classes={XdclassApplication.class})//启动整个springboot工程

public class SpringBootTests { }


MOCKMVC 模拟mvc请求 访问api接口


perform:执行一个RequestBuilder请求。

MockMvcRequestBuilders: 构建一个请求。

andExpect:断言。

MockMvcResultMatchers:验证规则。

andReturn:最后返回相应的MvcResult->Response。

getResponse:获取返回相应。

你可能感兴趣的:((四)SpringBoot的单元测试与MockMvc)