Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which assertion to use for a simple comparison between two variables in jmeter?

Tags:

jmeter

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.

like image 959
user3871995 Avatar asked Mar 13 '23 15:03

user3871995


1 Answers

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 failure

See How to Use JMeter Assertions in Three Easy Steps for more comprehensive information on using assertions.

like image 143
Dmitri T Avatar answered Apr 27 '23 03:04

Dmitri T