即使在 JMeter 的 JSON 断言中预期和实际匹配,如何修复 'Assertion failure:true'?

How to fix 'Assertion failure:true' even if the expected and the actual are matching in JSON assertion in JMeter?

对于 JMeter 4.0 中的 JSON 断言,预期值和实际值相同。但是,在 JSON 断言结果中,它说它不匹配。这甚至在 Excel 中进行了比较,以检查是否有任何空格或其他字符,并发现匹配。不确定为什么断言在 JMeter 中失败。

例如:

Assertion failure message: Value expected to match regexp '2019-03-25T16:06:36.162+0000', but it did not match: '2019-03-25T16:06:36.162+0000'

您是否勾选了'Match as regular expression'选项?如果是这样,那么您需要转义正则表达式特殊字符(. 和 +)并将您的断言值替换为 2019-03-25T16:06:36\.162\+0000

  1. 如果您不使用 Regular Expression 进行数据验证并且它是一个普通的字符串 - 只需取消选中“作为正则表达式匹配”框

  2. 如果 2019-03-25T16:06:36.162+0000 是一个正则表达式 - 它的格式不正确,因为您需要使用反斜杠转义 + 符号,因为 +meta-character 需要转义:

  3. According to JMeter Best Practices you should always be using the latest version of JMeter so consider upgrading to JMeter 5.1 (or whatever is the latest version available at JMeter Downloads页)