Jmeter JSON斷言和響應斷言的區別是什么?


 

假設響應數據是{"code":0,"datas":{"informationStatus":1}}

 

  響應斷言:"code":0,檢查點這樣寫就不會報錯,但是如果想驗證 "informationStatus":1,斷言結果就會出錯。

  這時候就需要使用JSON斷言。

  JSON斷言:$.datas.informationStatus,  預期結果填0,斷言通過。需要了解JSON Path表達式語法,很簡單,5分鍾不到就能搞定。

 

 

jsonPath基本語法:

 

基本練習:

{ "store": {
    "book": [ 
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      { "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99
      },
      { "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99
      },
      { "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  }
}

 

示例表達式:

$.store.book[*].author:商店所有書籍的作者(四個作者)

$..author :所有作者

$.store.* :商店所有的東西,包括book和bicycle

$.store..price :所有東西的價格

$..book[2] :第三本書

$..book[0,1] /$..book[:2] :前兩本書

 $..book[?(@.isbn)] :用isbn編號過濾所有書籍

$..book[?(@.price<10)] :過濾所有比10更便宜的書

$..* :XML文檔中的所有元素

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM