使用Jmeter进行REST API测试。当我在HTTP响应中使用JSON Path Tester时,提供了JSON Path表达式作为$..name
。获取以下匹配项
Done,
Won't Do,
Duplicate,
Cannot Reproduce
但当我放置相同的JSON表达式并导致JSON断言时,得到错误:-
Assertion error: false
Assertion failure: true
Assertion failure message: Value expected to match regexp '"Done","Won't Do","Duplicate","Cannot Reproduce"', but it did not match: '["Done","Won't Do","Duplicate","Cannot Reproduce"]'
发布于 2019-09-04 15:24:46
匹配多个值的
Arrays.asList(responseArray).contains("Done");nameLength = Integer.parseInt(vars.get("Name_matchNr"));String[] responseArray = StringnameLength;for (int i= 0;i< nameLength;i++) { responseArrayi = vars.get("Name_"+(i+1));} boolean test1 = int boolean test2 = Arrays.asList(responseArray).contains("Won't Do");boolean =布尔test4 =Arrays.asList(ResponseArray).contains(“无法重现”);if (test1 == false) { AssertionResult.setFailureMessage("Done not present in Response");AssertionResult.setFailure(true);} if (test2 == false) { AssertionResult.setFailureMessage("Won't not present in Response");AssertionResult.setFailure(true);} if (test3 == false) {AssertionResult.setFailureMessage(“Response not present”);AssertionResult.setFailure(true);} if (test4 == false) {AssertionResult.setFailureMessage(“无法再现响应中不存在”);AssertionResult.setFailure(true);}
与单值匹配的
Expected Value
部分中输入任意单个值:"Done/Won't Do/Duplicate/Cannot Reproduce"
发布于 2019-09-04 19:31:06
如果这确实是您要实现的目标,请考虑以下JSON Assertion配置:
以防“期望值”文本表示:
["Done","Won't Do","Duplicate","Cannot Reproduce"]
但是要知道,这种形式的断言将是脆弱的,并且对任何JSON更改都很敏感,即如果匹配的顺序不同,则断言将失败。因此,我更推荐使用The Easiest Way To Compare REST API Responses Using JMeter文章中描述的方法之一。
https://stackoverflow.com/questions/57782942
复制相似问题