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

信阳电子商务平台网站建设厦门网络推广公司

信阳电子商务平台网站建设,厦门网络推广公司,小程序直播系统开发,vi设计公司简介上文java springboot测试类鉴定虚拟MVC请求 返回内容与预期值是否相同我们讲了测试类中 虚拟MVC发送请求 匹配返回内容是否与预期值相同 但是 让我意外的是 既然没人骂我 因为我们实际开发 返回的基本都是json数据 字符串的接口场景是少数的 我们在java文件目录下创建一个 dom…

上文java springboot测试类鉴定虚拟MVC请求 返回内容与预期值是否相同我们讲了测试类中 虚拟MVC发送请求 匹配返回内容是否与预期值相同 但是 让我意外的是 既然没人骂我 因为我们实际开发 返回的基本都是json数据 字符串的接口场景是少数的
在这里插入图片描述
我们在java文件目录下创建一个 domain 文件夹
下面创建一个user类

参考代码如下

package com.example.webdom.domain;public class user {private int id;private String name;public void setId(int id) {this.id = id;}public void setName(String name) {this.name = name;}public int getId() {return id;}public String getName() {return name;}
}

这边 我就设置一下最基本的 id和name 然后声明一下对应的 get set函数

这边 我们 controller 代码更改如下

package com.example.webdom.controller;import com.example.webdom.domain.user;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/TextWeb")
public class TestWeb {@GetMappingpublic user getById(){user user = new user();user.setId(1);user.setName("数据管理");System.out.println("getById is running .....");return user;}
}

这里 我们直接 new 一个 user类对象 然后 set一下他的id和name
然后接口返回这个对象出去

将测试类 代码改写如下

package com.example.webdom;import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.ResultMatcher;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.ContentResultMatchers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
public class WebDomApplicationTests {@Testvoid contextLoads(@Autowired MockMvc mvc) throws Exception {MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/TextWeb");ResultActions action = mvc.perform(builder);ContentResultMatchers content = MockMvcResultMatchers.content();ResultMatcher result = content.json("{\"id\":1,\"name\":\"数据管理\"}");action.andExpect(result);}}

这里 我们因为还是判断内容 所以依旧用content
然后 里面写一个json格式的字符串即可

然后 我们右键测试函数运行
在这里插入图片描述
返回的json和这个json串是一样的 自然不会 有什么问题
在这里插入图片描述
我们重点还是要看错误的 这里 我爸 name 后面加一个1 让他匹配不上
在这里插入图片描述
然后 我们再次右键运行 出错 是我们想要的
在这里插入图片描述
这个位置的内容依旧这么给力 依旧告诉你了 到底是那个字段出问题了 name
然后告诉了你区别 可以说 非常只能了
在这里插入图片描述

http://www.hkea.cn/news/549982/

相关文章:

  • 专业网站设计公司有哪些秒收录关键词代发
  • 织梦网站模板源码下载真实有效的优化排名
  • 网站建设过程中什么最重要磁力链bt磁力天堂
  • html5企业网站案例鹤壁搜索引擎优化
  • 网站建设平台简介链接交换平台
  • 照片展示网站模板宁波seo咨询
  • 奉贤建设机械网站制作长沙网址seo
  • 上海企业网站模板建站常用的网络推广方法
  • 大连零基础网站建设教学培训济南seo优化公司
  • html 做网站案例简单网站推广建设
  • 践行新使命忠诚保大庆网站建设线上广告
  • 定制网站建设服务商商家联盟营销方案
  • 集团官网建设公司外贸seo推广公司
  • 佛山新网站制作平台网站诊断工具
  • 做PPT的网站canvawhois查询
  • 营销型网站建设吉林定制化网站建设
  • 个人网上公司注册流程图新站优化案例
  • 做se要明白网站明星百度指数排名
  • 网页微博草稿箱在哪西安seo推广优化
  • 嘉兴微信网站建设谷歌首页
  • 什么网站做海报b站不收费网站
  • 如何自己做个简单网站seo知识点
  • 有哪些做批发的网站有哪些手续百度推广优化是什么意思
  • 用阿里巴巴店铺做公司网站怎么样引擎搜索有哪些
  • 网页制作软件属于什么软件类别简述seo的优化流程
  • 网站建设 公司新闻谷歌排名网站优化
  • 怎样做自己的vip解析网站佛山外贸seo
  • 我的网站在百度搜不到了seo是什么职业做什么的
  • 网站私信界面国外网站seo免费
  • wordpress mysql类惠州网站seo