• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

mock测试:JMeter工具

武飞扬头像
^会飞的鱼Fly^
帮助1

接上文《mock框架与测试一
本文将简单介绍mock框架搭建完成后,使用JMeter执行接口验证测试的方法:
JMeter下载:
官网:https://jmeter.apache.org/

JMeter打开:
了解下jmeter打开方式:
1、JMeter解压路径bin文件夹下打开jmeter.bat,命令行窗口无需关闭。
学新通
2、通过ApacheJMeter.jar鼠标右键打开java程序
学新通
3、通过java指令,在当前目录打开命令行窗口,输入java -jar ApacheJMeter.jar
学新通
切入正题:使用jmeter执行接口测试
先启动moco服务:运行java -jar moco.jar包 协议 -p端口 -c json文件
学新通

1、 Moco框架的http协议get方法的Mock实现

  • 不带参数的get实现
[
  {
   "description":"This is Get request without paramter",
   "request":{
       "uri":"/getdemo",
       "method":"get"
   },
   "response":{
       "text":"This is response for Get request without paramter "
   }
  }
]

配置jmeter:
1、新建线程组——》新建http请求——》新增查看结果树
学新通
学新通
学新通
2、编辑请求
学新通
3、启动请求,查看响应返回数据
学新通

  • 带参数的get实现:
    线程组——》新建http请求——》添加结果树
    添加参数:
    学新通
    启动请求查看结果:
    学新通
    2、 Moco框架的http协议Post方法的Mock实现
  • 不带参数的post请求
[
  {
   "description":"This is Post request",
   "request":{
       "uri":"/postdemo",
       "method":"post"
   },
   "response":{
       "text":"This is Post response"
   }
  }
]

1、配置post请求
学新通
2、查看响应结果:
学新通

  • 带参数的post请求
[
{
   "description":"This is Post request with paramter",
   "request":{
       "uri":"/postwithparam",
       "method":"post",
       "forms":{
           "name":"zhangsan",
           "age":"18"
       }
   },
   "response":{
       "text":"This is Post response with paramter"
   }
  }
]
学新通

1、配置参数
学新通
2、查看响应结果:
学新通
3、 Moco框架如何加入Cookies

  • 带cookies信息的get请求
[
{
   "description":"This is Get request with cookies",
   "request":{
       "uri":"/get/with/cookies",
       "method":"get",
       "cookies":{
          "login":"true"
       }
   },
   "response":{
       "text":"This is get response with cookies"
   }
  }
]

1、配置cookie参数,新建该请求的cookie管理器-》配置cookie参数
学新通
学新通
2、查看响应结果:
学新通

  • 带cookies信息的post请求
[
{
   "description":"This is Post request with cookies",
   "request":{
       "uri":"/post/with/cookies",
       "method":"post",
       "cookies":{
          "login":"true"
       },
       "json":{
           "name":"zhangsan",
           "age":"18"
       }
   },
   "response":{
       "status":200,
       "json":{
          "zhangsan":"success",
           "status":"1"
       }
   }
  }
  ]
学新通

1、配置参数
学新通
学新通
2、查看响应结果
学新通
3、 Moco框架如何加入Header

  • Header请求头信息的格式在get和post请求中是一致的。
{
   "description":"This is Post request with header",
   "request":{
       "uri":"/postwithheader",
       "method":"post",
       "headers":{
           "content-type":"application/json"
       },
       "json":{
           "name":"zhangsan",
           "age":"18"
       }
   },
   "response":{
       "text":"This is Post response with paramter"
   }
  }
学新通

1、配置头参数
学新通学新通
2、查看响应数据
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhiajaif
系列文章
更多 icon
同类精品
更多 icon
继续加载