当前位置: 首页 > news >正文

玉环网站制作西安关键词快速排名

玉环网站制作,西安关键词快速排名,东莞做网站一年费用,wordpress支付下载地址springboot虚拟请求 表现层测试 web环境模拟测试 虚拟请求状态匹配——执行状态的匹配 Testvoid testStatus(Autowired MockMvc mvc) throws Exception { // //http://localhost:8080/books// 创建一个虚拟请求,当前访问的是booksMockHttpServletRequestBui…

springboot虚拟请求

表现层测试

web环境模拟测试

在这里插入图片描述
在这里插入图片描述

虚拟请求状态匹配——执行状态的匹配

    @Testvoid testStatus(@Autowired MockMvc mvc) throws Exception {
//       //http://localhost:8080/books// 创建一个虚拟请求,当前访问的是booksMockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/books1");ResultActions actions = mvc.perform(builder);//设定预期值,与真实值进行比较,成功测试通过,失败测试失败// 定义本次调用的预期值StatusResultMatchers status = MockMvcResultMatchers.status();// 预计本次调用时成功的状态200ResultMatcher ok = status.isOk();// 添加与机制到本次调用过程中进行匹配actions.andExpect(ok);}

虚拟请求状态匹配——执行内容的匹配

   @Testvoid testBody(@Autowired MockMvc mvc) throws Exception {
//       //http://localhost:8080/books// 创建一个虚拟请求,当前访问的是booksMockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/books");ResultActions actions = mvc.perform(builder);//设定预期值,与真实值进行比较,成功测试通过,失败测试失败// 定义本次调用的预期值ContentResultMatchers content = MockMvcResultMatchers.content();ResultMatcher result = content.string("springboot");// 添加与机制到本次调用过程中进行匹配actions.andExpect(result);}

虚拟请求状态匹配——执行内容的匹配(json)

 @Testvoid testJson(@Autowired MockMvc mvc) throws Exception {MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/books");ResultActions actions = mvc.perform(builder);//设定预期值,与真实值进行比较,成功测试通过,失败测试失败// 定义本次调用的预期值ContentResultMatchers content = MockMvcResultMatchers.content();ResultMatcher result = content.json("{\n" +"    \"id\": 1,\n" +"    \"name\": \"springBoot\",\n" +"    \"type\": \"springBoot\",\n" +"    \"description\": \"springBoot\"\n" +"}");// 添加与机制到本次调用过程中进行匹配actions.andExpect(result);}

在这里插入图片描述

这里面的东西都可以匹配

虚拟请求状态匹配——匹配响应头

@Testvoid testContentType(@Autowired MockMvc mvc) throws Exception {MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/books");ResultActions actions = mvc.perform(builder);//设定预期值,与真实值进行比较,成功测试通过,失败测试失败// 定义本次调用的预期值HeaderResultMatchers header = MockMvcResultMatchers.header();ResultMatcher contentType = header.string("Content-Type","application/json");// 添加与机制到本次调用过程中进行匹配actions.andExpect(contentType);}

实际应用的时候,可以把这些都放在一起
例如,把这些组合一下:

@Testvoid testGetById(@Autowired MockMvc mvc) throws Exception {MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/books");ResultActions actions = mvc.perform(builder);StatusResultMatchers status = MockMvcResultMatchers.status();ResultMatcher ok = status.isOk();actions.andExpect(ok);HeaderResultMatchers header = MockMvcResultMatchers.header();ResultMatcher contentType = header.string("Content-Type","application/json");actions.andExpect(contentType);ContentResultMatchers content = MockMvcResultMatchers.content();ResultMatcher result = content.json("{\n" +"    \"id\": 1,\n" +"    \"name\": \"springBoot\",\n" +"    \"type\": \"springBoot2\",\n" +"    \"description\": \"springBoot\"\n" +"}");actions.andExpect(result);}

数据层测试事务回滚

在这里插入图片描述

测试用例数据设定

在这里插入图片描述
配置一个对象来使用,比如:

package com.itheima.testcase.domain;import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;@Data
@Component
@ConfigurationProperties(prefix = "testcase.book")
public class BookCase {private int id;private int id2;private int type;private String name;private  String uuid;private long publishTime;
}
http://www.hkea.cn/news/664383/

相关文章:

  • 企业建设网站公司哪家好app拉新推广接单平台
  • 老虎淘客系统可以做网站吗江西省水文监测中心
  • 高港区企业网站建设快速建站教程
  • 怎样写企业网站建设方案北京网站seo招聘
  • 做蛋糕视频的网站软文广告范文
  • h5自适应网站模板下载网站换友链平台
  • 政府网站建设及管理规范各大搜索引擎入口
  • poedit pro wordpress免费网站推广优化
  • 市场营销产品推广策划方案seo合作代理
  • 东莞专业网站建设推广搜索引擎网络排名
  • 服务器做网站用什么环境好销售营销方案100例
  • 如何做DJ网站英文seo外链
  • 网站统计源码下载百度推广的步骤
  • 本地网站建设seo推广的方法
  • 东莞好的网站建设效果seo和sem分别是什么
  • 最新版wordpress背景手机网络优化软件
  • 丛台企业做网站推广免费建一级域名网站
  • 集宁网站建设免费网站推广网站破解版
  • 网站建设域名的购买有域名和服务器怎么建网站
  • 深圳有什么网站长沙百度seo
  • 台州企业网站模板建站怎么在百度上做公司网页
  • 烟台网站建设联系企汇互联专业网站维护收费标准
  • 网络客户服务平台搜索优化推广公司
  • 建设网站技术方案线上教育培训机构十大排名
  • 沈阳人流seo优化师就业前景
  • 开发区网站制作公司seo关键词有话要多少钱
  • 网站被篡改处理app拉新平台
  • 在线房屋设计网站seo推广平台服务
  • 电子政务门户网站建设代码短链接生成网址
  • 崔各庄地区网站建设百度非企渠道开户