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>
    
  • 相关阅读:
    canvas-8clip.html
    canvas-7globleCompositeOperation2.html
    canvas-7globleCompositeOperation.html
    canvas-7global.html
    canvas-6shadow.html
    canvas-6font.html
    A1036. Boys vs Girls
    A1006. Sign In and Sign Out
    A1011. World Cup Betting
    String 对象-->charAt() 方法
  • 原文地址:https://www.cnblogs.com/csj2018/p/11661362.html
Copyright © 2011-2022 走看看