美文网首页
(四)SpringBoot的单元测试与MockMvc

(四)SpringBoot的单元测试与MockMvc

作者: 丛鹏 | 来源:发表于2022-06-28 10:12 被阅读0次

单元测试

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:获取返回相应。

相关文章

网友评论

      本文标题:(四)SpringBoot的单元测试与MockMvc

      本文链接:https://www.haomeiwen.com/subject/odlovrtx.html