Reputation: 1223
I have a test which stores results in two variables and I want to do an assertion which returns a fail if they are not equal.
I know there are a number of different assertions available. I'd like to know which would be most appropriate for a simple comparison like this and how to use it.
Upvotes: 5
Views: 7869
Reputation: 168092
Beanshell Assertion will do the trick for you, relevant code will be:
String var1 = vars.get("first");
String var2 = vars.get("second");
Failure = !var1.equals(var2);
if (Failure) {
FailureMessage = "Variables are not equal. Expected \"" + var1 + "\" , actual:\"" + var2 + "\"";
}
Replace first
and second
with your variable names (without ${}
)
Failure
- is a pre-defined boolean variable, if it is "true" - impacted sampler(s) are considered as failed, otherwise - successful. FailureMessage
- custom string to describe the failureSee How to Use JMeter Assertions in Three Easy Steps for more comprehensive information on using assertions.
Upvotes: 10