3
我正在運行JSR223聲明,在此我使用groovy將預期響應與實際響應進行比較。如果不相等,斷言失敗。 這裏是代碼JMeter斷言結果
import groovy.json.JsonSlurper;
JsonSlurper slurper = new JsonSlurper();
boolean set_assertion = true;
def expected_response = slurper.parseText("<JSON response goes here>");
def actual_response = slurper.parseText(prev.getResponseDataAsString());
if (expected_response != actual_response)
{
set_assertion = false;
log.error("expected_response != actual_response");
assert set_assertion == true;
SampleResult.setSuccessful(false);
}
現在,斷言確實失敗。但我認爲它失敗了,因爲我在日誌中遇到了內部錯誤。 這是我的斷言結果。 Assertion Results 這裏是日誌
ERROR - jmeter.threads.JMeterThread: Error processing Assertion Assertion failed:
assert set_assertion == true
| |
false false
at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:402)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:650)
at Script48.run(Script48.groovy:16)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:352)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:153)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:206)
at org.apache.jmeter.assertions.JSR223Assertion.getResult(JSR223Assertion.java:47)
at org.apache.jmeter.threads.JMeterThread.processAssertion(JMeterThread.java:755)
at org.apache.jmeter.threads.JMeterThread.checkAssertions(JMeterThread.java:746)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:490)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:410)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:241)
at java.lang.Thread.run(Unknown Source)
理想我應該不會有錯誤,我應該斷言失敗,應具有以下結果「斷言錯誤:錯誤」和「斷言失敗:真」。
請你幫我理解我犯了什麼錯誤。我最關心的是日誌中的錯誤。謝謝!
你想要做斷言,但沒有它會拋出錯誤?不要以爲我明白...只是不要做斷言行 –
@tim_yates它不應該錯誤嗎?我有一個響應斷言失敗,但不會給我一個錯誤。 – Dummy