zoukankan      html  css  js  c++  java
  • 8-5接口测试用例设计与编写2 rest-assured

    rest-assured

    • 简约的接口测试DSL
    • 支持xml json的结构化解析
    • 支持xpath jsonpath gpath等多种解析方式
    • 对Spring的支持比较前面
    • 底层是httpclient
      加入访问http://localhost:8080/lotto/{id},返回结果如下
    {
       "lotto":{
          "lottoId":5,
          "winning-numbers":[2,45,34,23,7,5,3],
          "winners":[
             {
                "winnerId":23,
                "numbers":[2,45,34,23,3,5]
             },
             {
                "winnerId":54,
                "numbers":[52,3,12,11,18,22]
             }
          ]
       }
    }
    

    github地址
    编写测试用例

    public class StartRestAssured {
        @Test
        public void
        lotto_resource_returns_200_with_expected_id_and_winners() {
            when().
                    get("/lotto/{id}", 5).//发起一次请求,地址是"/lotto/5"
                    then().
                    statusCode(200).//返回码是200
                    body("lotto.lottoId", equalTo(5),//判断lotto.lottoId是5
                            "lotto.winners.winnerId", hasItems(23, 54));//lotto.winnners.winnerId包含23,54
    
        }
    }
    

    先添加依赖

    <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>4.0.0</version>
        <scope>test</scope>
    </dependency>
    
  • 相关阅读:
    Clam and fish
    费马小定理求逆元模板题
    1
    DP 习题
    106. 从中序与后序遍历序列构造二叉树
    计算几何(判断四边形形状)
    中国剩余定理
    BFS模板
    DFS模板
    线段树
  • 原文地址:https://www.cnblogs.com/csj2018/p/11661362.html
Copyright © 2011-2022 走看看