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

ChatGPT与Postman协作完成接口测试(二)

    ChatGPT生成的Postman接口测试用例脚本如下所示。

ChatGPT生成的Postman接口测试用例脚本

以下是符合Collection v2.1格式要求的 Postman 测试用例脚本,覆盖了正常注册和密码不匹配两种情况的测试:

{

  "info": {

    "_postman_id": "09e63d0d-9a62-4c3b-8a2d-76f352a12312",

    "name": "用户注册接口测试",

    "description": "测试用户注册接口的正常和异常情况",

    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"

  },

  "item": [

    {

      "name": "正常注册",

      "request": {

        "method": "POST",

        "header": [],

        "body": {

          "mode": "urlencoded",

          "urlencoded": [

            {

              "key": "username",

              "value": "testuser",

              "type": "text"

            },

            {

              "key": "password",

              "value": "testpassword",

              "type": "text"

            },

            {

              "key": "passwordConfirm",

              "value": "testpassword",

              "type": "text"

            },

            {

              "key": "firstName",

              "value": "John",

              "type": "text"

            },

            {

              "key": "lastName",

              "value": "Doe",

              "type": "text"

            },

            {

              "key": "address1",

              "value": "123 Main St",

              "type": "text"

            },

            {

              "key": "address2",

              "value": "98765",

              "type": "text"

            },

            {

              "key": "register.x",

              "value": "1.23",

              "type": "text"

            },

            {

              "key": "register.y",

              "value": "4.56",

              "type": "text"

            }

          ]

        },

        "url": {

          "raw": "http://127.0.0.1:1080/cgi-bin/login.pl",

          "protocol": "http",

          "host": [

            "127",

            "0",

            "0",

            "1"

          ],

          "port": "1080",

          "path": [

            "cgi-bin",

            "login.pl"

          ]

        }

      },

      "response": []

    },

    {

      "name": "密码不匹配",

      "request": {

        "method": "POST",

        "header": [],

        "body": {

          "mode": "urlencoded",

          "urlencoded": [

            {

              "key": "username",

              "value": "testuser",

              "type": "text"

            },

            {

              "key": "password",

              "value": "testpassword",

              "type": "text"

            },

            {

              "key": "passwordConfirm",

              "value": "mismatchedpassword",

              "type": "text"

            }

          ]

        },

        "url": {

          "raw": "http://127.0.0.1:1080/cgi-bin/login.pl",

          "protocol": "http",

          "host": [

            "127",

            "0",

            "0",

            "1"

          ],

          "port": "1080",

          "path": [

            "cgi-bin",

            "login.pl"

          ]

        }

      },

      "response": []

    }

  ]

}

您可以将此 Postman 测试用例脚本导入到 Postman 应用程序中,然后执行这些测试用例以验证用户注册接口的正常和异常情况。希望这对您有所帮助!

        从ChatGPT生成的Postman测试用例脚本中,可以看到其覆盖了正常注册和密码不匹配异常注册这两种情况。这符合笔者的预期,所以复制生成的代码,并将其存储到D:\AIBOOK\S_PM_WebTours.json文件中。

  • 接口测试用例评审

       通常情况下,接口测试用例也需要进行测试团队的内部评审,关于评审过程的内容在此不赘述。对已生成的Postman测试用例脚本进行评审,鉴于笔者只想考察正常注册和密码不匹配异常注册这两种情况下接口是否可以正常处理,而生成的Postman测试用例脚本完全满足需求,所以不需要扩展更多的内容。在实际工作中,需酌情处理,先评审ChatGPT生成的Postman测试用例脚本是否达到了预期目标,而后进行处理。

    S_PM_WebTours.json文件的内容如下。

S_PM_WebTours.json文件的内容

{

  "info": {

    "_postman_id": "09e63d0d-9a62-4c3b-8a2d-76f352a12312",

    "name": "用户注册接口测试",

    "description": "测试用户注册接口的正常和异常情况",

    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"

  },

  "item": [

    {

      "name": "正常注册",

      "request": {

        "method": "POST",

        "header": [],

        "body": {

          "mode": "urlencoded",

          "urlencoded": [

            {

              "key": "username",

              "value": "testuser",

              "type": "text"

            },

            {

              "key": "password",

              "value": "testpassword",

              "type": "text"

            },

            {

              "key": "passwordConfirm",

              "value": "testpassword",

              "type": "text"

            },

            {

              "key": "firstName",

              "value": "John",

              "type": "text"

            },

            {

              "key": "lastName",

              "value": "Doe",

              "type": "text"

            },

            {

              "key": "address1",

              "value": "123 Main St",

              "type": "text"

            },

            {

              "key": "address2",

              "value": "98765",

              "type": "text"

            },

            {

              "key": "register.x",

              "value": "1.23",

              "type": "text"

            },

            {

              "key": "register.y",

              "value": "4.56",

              "type": "text"

            }

          ]

        },

        "url": {

          "raw": "http://127.0.0.1:1080/cgi-bin/login.pl",

          "protocol": "http",

          "host": [

            "127",

            "0",

            "0",

            "1"

          ],

          "port": "1080",

          "path": [

            "cgi-bin",

            "login.pl"

          ]

        }

      },

      "response": []

    },

    {

      "name": "密码不匹配",

      "request": {

        "method": "POST",

        "header": [],

        "body": {

          "mode": "urlencoded",

          "urlencoded": [

            {

              "key": "username",

              "value": "testuser",

              "type": "text"

            },

            {

              "key": "password",

              "value": "testpassword",

              "type": "text"

            },

            {

              "key": "passwordConfirm",

              "value": "mismatchedpassword",

              "type": "text"

            }

          ]

        },

        "url": {

          "raw": "http://127.0.0.1:1080/cgi-bin/login.pl",

          "protocol": "http",

          "host": [

            "127",

            "0",

            "0",

            "1"

          ],

          "port": "1080",

          "path": [

            "cgi-bin",

            "login.pl"

          ]

        }

      },

      "response": []

    }

  ]

}

  • 接口测试用例迭代与完善

        如果想要完善接口测试用例,可以依据笔者前面使用的方法,让ChatGPT继续完善测试用例,如关键字过长、特殊字符等接口测试用例。限于篇幅,这里不考虑这些内容。S_PM_WebTours.json文件就是最终的Postman接口测试用例脚本。

未完待续


http://www.kler.cn/a/450385.html

相关文章:

  • AtCoder Beginner Contest 385(A~F)题解
  • [WASAPI]从Qt MultipleMedia来看WASAPI
  • 工控触摸屏用winForms来构建框架,效果还是很不错的
  • 初学stm32 --- NVIC中断
  • 基于Springboot + vue实现的汽车资讯网站
  • 2、光同步数字传送网的特点
  • 1 SpringBoot——项目搭建
  • Web 第一次作业 初探html 使用VSCode工具开发
  • 后端-redis
  • Git远程仓库的使用
  • 【唐叔学算法】第21天:超越比较-计数排序、桶排序与基数排序的Java实践及性能剖析
  • 探索数据可视化的利器:Matplotlib
  • 【云原生】kubeadm搭建的kubernetes1.28集群上自建ingress-nginx服务
  • 【Qt】了解和HelloWorld
  • 【每日学点鸿蒙知识】AVCodec、SmartPerf工具、web组件加载、监听键盘的显示隐藏、Asset Store Kit
  • Spring Web MVC:功能端点(Functional Endpoints)
  • Java AOP 介绍与实践
  • amazon广告授权
  • Django 模型管理器中自定义方法和添加导出功能
  • 聊聊volatile的实现原理?
  • conda 环境报错error while loading shared libraries: libpython3.9.so.1.0
  • 日志和MVCC的详解
  • JavaScript查缺补漏
  • Windows、CentOS环境下搭建自己的版本管理资料库:GitBlit
  • #渗透测试#漏洞挖掘#红蓝攻防#漏洞挖掘#未授权漏洞-Es未授权漏洞
  • 如何保障多个Facebook账号稳定运行:一账号一稳定IP?