问题
How can I set in Jmeter the conditions to establish that a sample has been a success or a failure according to its response time?
For example making Jmeter to consider that a sample with a response time above 10000 milliseconds is a fail and a sample with a response time under 10000 milliseconds is a success.
回答1:
Add Duration Assertion as a child to the sampler in which you want to assert the response times.
In Duration in milliseconds
field, add value 10000
.
回答2:
Below code will work in Beanshell Assertion. In addition, it will abort the current iteration and the virtual user will proceed to the next iteration from the beginning
try {
Long restime = SampleResult.getTime();
if (restime > 10000) {
Failure = true;
ctx.setRestartNextLoop(true);
}
else {
Failure = false;
//AssertionResult.setFailure(false);
}
}
catch ( Exception ex) {
Failure = true;
ctx.setRestartNextLoop(true);
}
来源:https://stackoverflow.com/questions/42092776/setting-faillure-conditions-in-jmeter