Jmeter-JSON提取器-提取确切的十进制值的问题

问题描述 投票:1回答:1

我正在编写一个测试来断言json中的所有金额值都包含小数点后的2位数字。从Json读取十进制值时,JSON提取器似乎忽略零。因此,例如8.50将是8.5,因此确切的断言将失败。

Sample Json,我添加到虚拟采样器中

{
    "shop": {
        "book": [
            {
                "author": "Author 1",
                "title": "Title 1",
                "price": 8.50
            },
        ],
        }
    },
}

我的价格响应断言设置为8.50

Assertion result

在结果中我失败了,因为它表明提取了8.5而不是8.50

是否有必要采取任何步骤来强制提取器完全读取json中显示的值?

json jmeter extract
1个回答
0
投票

JMeter的JSON断言依赖于JayWay JsonPath,并且此基础库内部存在错误。

[您可能想要report this issue at their GitHub,并且如果/一旦它会被解决-create an enhancement request for JMeter以使用此更新更好的库。

同时,您可以使用JSR223 Assertion作为替代方法,相关的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)
}

更多信息:

© www.soinside.com 2019 - 2024. All rights reserved.