Jmeter Randomization Part 1 – Random

When running load tests with jmeter, we are primarily concerned with the overall performance of the application.  If functional testing is a secondary concern, running the exact same data over and over again is an easy habit to fall into.

In any type of test suite, it is a best practice to vary the data.  If you are using a CSV data file to drive the test, you can vary the data in your test rows.  Keep in mind that the CSV is a finite list which can be recycled when using jmeter’s CSV Data Set Config.

Luckily there are a number of ways to randomize your data inside jmeter.  In this tutorial series we are going to look at how to randomize your test data during runtime.

Inside this UDV is a javascript function which generates a random integer between the range of 300 and 900:

01_udvRand

However, since this randomization is happening inside the UDV, the value is only randomized once at the beginning of the test.  So if the randomized value is 777, that variable value will not change and will be 777 for all threads.

If you want to randomize values for all threads, you need to use a processor.

In this example we will use a JSR223 Pre Processor with a few lines of java:

//randomize credit score
int RNDSCR = ${__Random(300, 900)};
log.info("RNDSCR = " + RNDSCR);

This is what you should see in the log console (with different random values for every thread):

02_logConsole