soapui mock数据测试
来源:互联网 发布:淘宝出售二手闲置 编辑:程序博客网 时间:2024/04/30 18:53
下载soapui工具并安装
https://www.soapui.org/downloads/latest-release.html打开工具,新建“工程”-“Mock server”
(1)右击选择“Create Empty Project”创建工程(2)右击选择“New REST Mock Server”
选择MockServer,右击选择“Add new mock action”,选择接口服务的方法和URL
选添加的动作action,右击选择“New MockResponse”,输入名称为“test1”
添加请求头信息和返回json串
设置mockserver访问端口和地址,并启动mock,访问mock的接口,模拟终端使用的数据
在soapui中调用mock的接口,访问http://192.168.1.106:8080/yst-test/findTabbar.json,返回的是mock的返回数据
mock接口通过请求参数返回不同的结果,通过script来实现
(1)创建多个mock response,不同的返回值
(2)编辑response返回个性值的script脚本,跟请求参数tabbarId的值返回相应的response
// Script dispatcher is used to select a response based on the incoming request.// Here are few examples showing how to match based on path, query param, header and body// Match based on pathdef requestPath = mockRequest.getPath()log.info "Path: "+ requestPathif( requestPath.contains("json1") ){ // return the name of the response you want to dispatch return "JSON Response"}// Match based on query parameterdef queryString = mockRequest.getRequest().getQueryString()log.info "QueryString: " + queryStringif( queryString.contains("tabbarId=1") ){ // return the name of the response you want to dispatch return "test2"}else if( queryString.contains("tabbarId=2") ){ // return the name of the response you want to dispatch return "test1"}// Match based on headerdef acceptEncodingHeaderList = mockRequest.getRequestHeaders().get("Accept-Encoding")log.info "AcceptEncoding Header List: " + acceptEncodingHeaderListif( acceptEncodingHeaderList.contains("gzip,deflate") ){ // return the name of the response you want to dispatch return "GZiped Response"}// Match based on bodydef requestBody = mockRequest.getRequestContent()log.info "Request body: " + requestBodyif( requestBody.contains("some data") ){ // return the name of the response you want to dispatch return "Response N"}
如果实在本地运行mock服务且mock的值存在中文,接口访问值容易出现乱码,可部署在tomcat的服务器中访问
导出到war包,并放入tomcat运行
阅读全文
0 0
- soapui mock数据测试
- 【SoapUI】2、SoapUI进行API Mock测试分析
- SoapUI———mock数据工具
- soapUI mock sevice
- 使用SoapUI mock REST API
- 使用SoapUI快速创建mock
- mock 测试
- mock测试
- MOCK测试
- mock测试
- mock 测试
- mock测试
- Mock测试
- mock测试
- mock测试
- mock测试
- mock测试
- Mock测试
- ubuntu 安装codeblocks教程 一遍安装成功
- 华中农业大学第五届程序设计大赛 A Little Red Riding Hood [BIT优化dp]【动态规划】
- 两个栈实现一个队列
- 关于随机森林和GBDT的一些思考
- 1196: 最后的胜利者
- soapui mock数据测试
- Linux搭建Hive On Spark环境(spark-1.6.3-without-hive+hadoop2.8.0+hive2.1.1)
- Jamie's Contact Groups UVALive
- Codeforces Round #426 (Div. 2) D. The Bakery(DP+线段树) 好题
- 2017.5.21入门组总结
- centos系统yum安装mysql
- POJO映射器的ModelMapper使用
- day8 socket编程CS模型完善错误处理
- 2017华为软挑---SPFA、ZKW、模拟退火