接口用例、流程及newman

接口的功能测试维度:单接口(正向和反向)和业务接口(一般做正向测试)

接口测试的测试用例编写:

  不单单针对参数值正确与否进行,还可以针对参数本身进行测试

正向参数----必选参数:所有的必选(必填参数)都包含

      组合参数:所有的必选+任意一个或多个可选参数

        全部参数:所有的必选+所有的可选参数     

反向参数----多参:多出一个或多个必选参数

         少参:缺少一个或多个必选参数

         无参:没有必选参数

      错误参数:参数名输入有误

单接口测试用例要素:

编号、用例名(标题)、模块、优先级、前置条件、请求方法、URL、请求头、请求体(请求数据)、预期结果

业务场景接口测试用例要素:最少的用例覆盖最多的接口

 

 接口测试的流程:

1、查看api文档,了解业务逻辑及接口调用(无或文档不全,使用fiddler抓包)

2、编写接口的测试用例,用例测试点不止对接口的参数数值做测试,还要做参数本身做测试

单接口做正向和反向测试

正向:必选、组合、所有

反向:多参、少参、无参、错误参数

业务调用接口一般做正向测试,最少的用例覆盖最多的接口

3、使用postman或jmeter,对接口的参数化(csv或json)及接口参数的关联(json提取器或正则表达式提取参数值,设置全局或环境变量实现接口关联)

4、编写接口断言及接口用例的管理(csv或json数据驱动)

5、postman+newman实现接口测试的执行及输出报告

6、newman+postman+Jenkins实现持续集成

 

postman+newman安装:

npm -v 查看newman,无版本号则先下载nodejs(官网下载安装)、npm install -g newman-reporter-allure (安装allure报告)

npm install -g newman (在线安装newman) 、npm install -g newman-reporter-html (在线安装html报告)

执行命令:newman run 

常用参数:

  -e 使用环境变量

  -g 使用全局变量

  -d 使用csv,json数据驱动

  -n 循环次数

  -r cli,html,json,junit --report-html-export  生成html报告

应用步骤:1、导出用例,环境变量,全局变量,数据文件   json格式

     2、运行并生成html报告 (非GUI模式运行)

      eg:   newman run "e:\postman_test\case\Test_collection.json" -e "e:\postman_test\case\environment.json" -g "e:\postman_test\case\globals.json" -r cli,allure --reporter-allure-export "e:\postman_test\allure_report"                     

        1、 allure serve "e:\postman_test\allure_report" (直接看结果)

        2、 allure generate "e:\postman_test\allure_report"  -o "e:\postman_test\allure_html"  --clean

            allure open "e:\postman_test\allure_html"(生成html后,通过allure open渲染后查看html文件)

      eg:   newman run "e:\postman_test\case\Test_collection.json" -e "e:\postman_test\case\environment.json" -g "e:\postman_test\case\globals.json" -r cli,html,json,junit --reporter-html-export "e:\postman_test\report_newman.html"

posted @ 2022-06-30 15:05  非同凡响  阅读(158)  评论(0编辑  收藏  举报