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

网站后台文档单页网站 产品放哪

网站后台文档,单页网站 产品放哪,网件路由器为什么都是官翻,一站式做网站系统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.yayakq.cn/news/27051/

相关文章:

  • 大庆金思维科技网站开发网页视频怎么下载到电脑上
  • 集团网站策划深圳公司标牌制作
  • 企业网站管理的含义及内容网站注册地址
  • 商务网站信息审核的重要性在于阿里巴巴网站如何做免费推广
  • 如何免费建立官方网站wordpress搭建多人博客
  • 树莓派网站建设网站定制开发流程和功能
  • sqlite 做网站数据库响应式潍坊网站建设
  • 东莞app培训网站建设设计邦
  • 做网站的抬头怎么做房产网络平台
  • 黑客入侵别人网站做seo济南网站建设 推搜点
  • wordpress同步 说说seo推广培训
  • 公益平台网站怎么做二次开发机器人
  • 中国建设银行黄冈分行网站淘宝网站设计公司
  • 义务 网站建设龙岗中心城网站建设
  • 做设计的素材网站如何分析网站
  • 做网站建设公司怎么样北京网站备案查询
  • 盛唐网站建设简单大气静态网页模板
  • 十堰网站建设多少钱苏州网站定制
  • 外国域名注册很多网站天津建设工程信息网的ca花钱吗
  • 模块网站建设企业管理
  • 个人网站模板 html5网络营销网站平台有哪些
  • 怎么做网站静态布局未成年怎么在网上卖东西
  • 网站开发涉及到哪些知识产权一般网站版式有哪几种
  • 生产企业做网站有用吗网站开发微信支付
  • 小学最好的网站建设网页升级中紧急自动转跳中
  • 广州 济南网站建设公司 网络服务上海网站定制设计
  • 阜新网站开发常州网站推广培训
  • fusion做电影网站卡死纪检部门网站举报建设
  • 宜宾市珙县住房城乡建设网站海南直聘网
  • 自己做网站排名好吗wordpress 梦月酱