JMeter练习(三):JMeter接口测试,依据接口文档,实现对MySQL库表的增删改查

目录

1. 新增用例

1.1 接口文档

1.2 在JMeter中,通过接口,实现往MySQL数据库中新增用例的功能

2. 查找单条用例

2.1 接口文档

2.2 在JMeter中,通过接口,查询MySQL数据库表中单条用例

3. 查询多条用例(分页查询)

3.1 接口文档

3.2  在JMeter中,通过接口,查询MySQL数据库表中多条用例,即分页查询

4. 编辑用例

4.1 接口文档

4.2  在JMeter中,通过接口,编辑MySQL数据库表的单条用例

5. 删除用例

5.1 接口文档

5.2  在JMeter中,通过接口,编辑MySQL数据库表的单条用例

【写在前面】

今天在JMeter中,通过HTTP请求取样器,结合之前项目定义的接口,实现了通过JMeter来对MySQL数据库进行增删改查的操作。

这里仅做学习记录。

1. 新增用例

1.1 接口文档

URL: /api/case
Method: POST
请求Body:
{
  "body": "string",
  "caseName": "string",
  "headers": [
    {
      "key": "string",
      "value": "string"
    }
  ],
  "id": 0,
  "method": "string",
  "regExtractor": {
    "caseId": 0,
    "createTime": "2022-03-08T04:25:33.414Z",
    "defaultValue": "string",
    "id": 0,
    "matchNum": "string",
    "regExpression": "string",
    "template": "string",
    "updateTime": "2022-03-08T04:25:33.414Z",
    "varName": "string"
  },
  "respAssertion": {
    "caseId": 0,
    "createTime": "2022-03-08T04:25:33.414Z",
    "id": 0,
    "patterns": "string",
    "updateTime": "2022-03-08T04:25:33.414Z"
  },
  "url": "string"
}

响应内容:
{
  "status": 200,
  "msg": "新增用例成功",
  "data": {
    "id": 1,
    "caseName": "string",
    "method": "string",
    "url": "string",
    "headers": [
      {
        "key": "string",
        "value": "string"
      }
    ],
    "body": "string",
    "regExtractor": {
      "id": 1,
      "caseId": 1,
      "varName": "string",
      "regExpression": "string",
      "template": "string",
      "matchNum": "string",
      "defaultValue": "string",
      "createTime": "2022-03-08T04:25:38.268+00:00",
      "updateTime": "2022-03-08T04:25:38.268+00:00"
    },
    "respAssertion": {
      "id": 1,
      "caseId": 1,
      "patterns": "string",
      "createTime": "2022-03-08T04:25:38.394+00:00",
      "updateTime": "2022-03-08T04:25:38.394+00:00"
    }
  }
}

1.2 在JMeter中,通过接口,实现往MySQL数据库中新增用例的功能

(1)打开IDEA,启动SpringBoot项目,在该SpringBoot项目中,定义了各个接口的实现。

(2)JMeter中,添加HTTP信息头管理器

 (3)JMeter中,添加HTTP信息头管理器

(4) JMeter中,添加HTTP请求取样器:新增用例

(5)保存,运行,察看结果树

(6)到数据库表中查看,新增用例是否已成功

 

2. 查找单条用例

2.1 接口文档

URL: /api/case/{id}
Method: GET
请求Body:
{
	“id”: Integer,
}

响应内容:
{
  "status": 200,
  "msg": "通过ID查询单条用例成功",
  "data": {
    "id": 1,
    "caseName": "case1",
    "method": "get",
    "url": "http://www.baidu.com",
    "headers": [
      {
        "key": "content-type",
        "value": "application/json"
      }
    ],
    "body": "body1",
    "regExtractor": {
      "id": 1,
      "caseId": 1,
      "varName": "var1",
      "regExpression": "r",
      "template": "$1$",
      "matchNum": "1",
      "defaultValue": "-1",
      "createTime": "2022-03-08T06:38:04.000+00:00",
      "updateTime": "2022-03-08T06:38:04.000+00:00"
    },
    "respAssertion": {
      "id": 1,
      "caseId": 1,
      "patterns": "200",
      "createTime": "2022-03-08T06:38:04.000+00:00",
      "updateTime": "2022-03-08T06:38:04.000+00:00"
    }
  }
}

2.2 在JMeter中,通过接口,查询MySQL数据库表中单条用例

(1)打开IDEA,启动SpringBoot项目,在该SpringBoot项目中,定义了各个接口的实现

同上

(2)JMeter中,添加HTTP信息头管理器

同上

(3)JMeter中,添加HTTP信息头管理器

同上

(4) JMeter中,添加HTTP请求取样器:查询单条用例

(5)保存,运行,察看结果树

 

3. 查询多条用例(分页查询)

3.1 接口文档

URL: /api/case/list
Method: GET
请求Body:
{
	“caseName”: “String”,
	“currentPage”: Integer,
	“pageSize”: Integer,
}

响应内容:
{
  "status": 200,
  "msg": "success",
  "data": [
    {
      "id": 1,
      "caseName": "case1",
      "method": "get",
      "url": "http://www.baidu.com",
      "headers": [
        {
          "key": "content-type",
          "value": "application/json"
        }
      ],
      "body": "body1",
      "regExtractor": null,
      "respAssertion": null
    }
  ],
  "current": 1,
  "pageSize": 1,
  "total": 1
}

3.2  在JMeter中,通过接口,查询MySQL数据库表中多条用例,即分页查询

(1)打开IDEA,启动SpringBoot项目,在该SpringBoot项目中,定义了各个接口的实现

同上

(2)JMeter中,添加HTTP信息头管理器

同上

(3)JMeter中,添加HTTP信息头管理器

同上

(4) JMeter中,添加HTTP请求取样器:查询多条用例,分页查询

(5)保存,运行,察看结果树

 

4. 编辑用例

4.1 接口文档

URL: /api/case
Method: PUT
请求Body:
{
  "body": "body11111",
  "caseName": "case1",
  "headers": [
    {
      "key": "content-type",
      "value": "application/json"
    }
  ],
  "id": 1,
  "method": "get",
  "regExtractor": {
    "caseId": 1,
    "createTime": "2022-03-08T04:25:33.414Z",
    "defaultValue": "-1",
    "id": 0,
    "matchNum": "1",
    "regExpression": "r",
    "template": "$1$",
    "updateTime": "2022-03-08T04:25:33.414Z",
    "varName": "var1"
  },
  "respAssertion": {
    "caseId": 1,
    "createTime": "2022-03-08T04:25:33.414Z",
    "id": 0,
    "patterns": "200",
    "updateTime": "2022-03-08T04:25:33.414Z"
  },
  "url": "http://www.baidu.com"
}

响应内容:
{
    "msg": "编辑用例成功",
    "data": {
        "headers": [
            {
                "value": "application\/json",
                "key": "content-type"
            }
        ],
        "regExtractor": {
            "template": "$1$",
            "varName": "var1",
            "matchNum": "1",
            "createTime": "2022-03-08T04:25:33.414+00:00",
            "defaultValue": "-1",
            "caseId": 1,
            "updateTime": "2022-03-08T07:50:48.692+00:00",
            "id": 1,
            "regExpression": "r"
        },
        "method": "get",
        "respAssertion": {
            "createTime": "2022-03-08T04:25:33.414+00:00",
            "caseId": 1,
            "patterns": "200",
            "updateTime": "2022-03-08T07:50:48.766+00:00",
            "id": 1
        },
        "caseName": "case1",
        "id": 1,
        "body": "body11111",
        "url": "http:\/\/www.baidu.com"
    },
    "status": 200
}

 

4.2  在JMeter中,通过接口,编辑MySQL数据库表的单条用例

(1)打开IDEA,启动SpringBoot项目,在该SpringBoot项目中,定义了各个接口的实现

同上

(2)JMeter中,添加HTTP信息头管理器

同上

(3)JMeter中,添加HTTP信息头管理器

同上

(4) JMeter中,添加HTTP请求取样器:编辑单条用例

(5)保存,运行,察看结果树 

 

5. 删除用例

5.1 接口文档

URL: /api/case/{id}
Method: DELETE
请求Body:
{
	“id”: Integer,
}

响应内容:
{
  "status": 200,
  "msg": "删除用例成功",
  "data": {
    "id": 1,
    "caseName": "case1",
    "method": "get",
    "url": "http://www.baidu.com",
    "headers": [
      {
        "key": "content-type",
        "value": "application/json"
      }
    ],
    "body": "body11111",
    "regExtractor": null,
    "respAssertion": null
  }
}

5.2  在JMeter中,通过接口,编辑MySQL数据库表的单条用例

(1)打开IDEA,启动SpringBoot项目,在该SpringBoot项目中,定义了各个接口的实现

同上

(2)JMeter中,添加HTTP信息头管理器

同上

(3)JMeter中,添加HTTP信息头管理器

同上

(4) JMeter中,添加HTTP请求取样器:删除单条用例

(5)保存,运行,察看结果树 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值