接口自动化测试集

cucumber框架+rest-assured框架+jsonPa

2021-01-04  本文已影响0人  Coding测试

整体项目关注点

接口测试实战(整个框架不仅仅局限于接口测试)

只关注cucumber的feature约束文件书写,即可完成接口测试。
废话不多说直接进入实战

cucumber框架+rest-assured框架+jsonPath框架各自的使用请自行百度查询

Feature: ["获取access_token"]

  Scenario Outline: 获取access_token
    Given API "/cgi-bin/gettoken"
    And Param
    """
    corpid : ww27d6f876d80ceec6
    corpsecret: yiXycY2QFDwD9HysYNk6hF7NFnt1CxBybuei1YKVaVw
    """
    When GET
    Then STATUS "200"
    Then JSONPATH_ASSERT "<jsonPath>" equals "<value>"
    Then JSONPATH_GET_MONGO
    |access_token|getToken|
    Examples:
      | jsonPath | value  |
      | errmsg   | ok |

2、读取人员接口

Feature: ["读取人员接口"]

  Scenario Outline: 读取人员接口_正向測試
    Given API "/cgi-bin/user/get"
    And Param
    """
    access_token: ${getToken}
    userid: CuiZhongYuan
    """
    When GET
    Then STATUS "200"
    Then JSONPATH_ASSERT "<jsonPath>" equals "<value>"
    Examples:
      | jsonPath | value  |
      | errmsg   | ok |

  Scenario Outline: 读取人员接口_逆向测试(缺少token鉴权,期望的错误)
    Given API "/cgi-bin/user/get"
    And Param
    """
    access_token:
    userid: CuiZhongYuan
    """
    When GET
    Then STATUS "200"
    Then JSONPATH_ASSERT "<jsonPath>" equals "<value>"
    Examples:
      | jsonPath | value  |
      | errcode   | 41001 |
Feature: ["新增成员接口"]

  Scenario Outline: 新增人员接口_正向测试
    Given API "/cgi-bin/user/create?access_token=${getToken}"
    And Body
    """
     {
      "userid": "TESTER",
      "name": "张三",
      "alias": "jackzhang",
      "mobile": "13800000004",
       "department": [2],
      }
    """
    When POST
    Then STATUS "200"
    Then JSONPATH_ASSERT "<jsonPath>" equals "<value>"
    Examples:
      | jsonPath | value  |
      | errcode  | 0      |


请求参数类型说明

Param:支持url路径跟的参数和form-data格式参数
Body: 支持raw原生的json格式参数


变量定义和取值

测试运行结果

Jenkins插件cucumber美化报告直观

项目源码地址:点击查看

        <dependency>
            <groupId>com.weixin.api</groupId>
            <artifactId>cuke</artifactId>
            <version>jxc_2.2.2</version>
            <scope>test</scope>
        </dependency>
上一篇下一篇

猜你喜欢

热点阅读