单元测试
1、pom引入相关依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
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:获取返回相应。