Jmeter-JSON提取器-提取精确十进制值的问题
我正在编写一个测试来断言json中的所有金额值都包含小数点后的2位数字。 当从JSON中读取十进制值时,JSON提取器似乎忽略了零。因此,例如8.50将是8.5,因此精确的断言将失败 我添加到虚拟采样器的示例JsonJmeter-JSON提取器-提取精确十进制值的问题,json,jmeter,extract,Json,Jmeter,Extract,我正在编写一个测试来断言json中的所有金额值都包含小数点后的2位数字。 当从JSON中读取十进制值时,JSON提取器似乎忽略了零。因此,例如8.50将是8.5,因此精确的断言将失败 我添加到虚拟采样器的示例Json { "shop": { "book": [ { "author": "Author 1", "title": "Title 1", "pr
{
"shop": {
"book": [
{
"author": "Author 1",
"title": "Title 1",
"price": 8.50
},
],
}
},
}
我对价格的响应断言设置为8.50
在结果中,我得到了一个失败,因为它表明提取了8.5而不是8.50
是否需要执行任何步骤来强制提取器读取与json中显示的值完全相同的值?JMeter的json断言依赖于此,并且此基础库中存在一个bug 您可能想使用这个新的更好的库,如果/一旦它得到解决 同时,您可以使用相关的Groovy代码作为解决方案:
def expectedPrice = 8.50
def actualPrice = new groovy.json.JsonSlurper().parse(prev.getResponseData()).shop.book[0].price
if (expectedPrice != actualPrice) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage('Price mismatch, expected: ' + expectedPrice + ', got: ' + actualPrice)
}
更多信息:
def expectedPrice = 8.50
def actualPrice = new groovy.json.JsonSlurper().parse(prev.getResponseData()).shop.book[0].price
if (expectedPrice != actualPrice) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage('Price mismatch, expected: ' + expectedPrice + ', got: ' + actualPrice)
}
更多信息: