Keyur Golani
Keyur Golani

Reputation: 583

Randomize path in JMeter REST API load testing

So I have a REST API that I want to test with JMeter. I have few different paths in the REST Service.

If we take an example of simple REST service that will calculate based on two values passed in request, I have four different paths /add /sub /mul /div

Now I want to test this with a 5000 requests but want to randomize the path and the values in request parameters in each request. Also if possible, want to get the results in 4 categories separately for each path.

Can someone please suggest the right combination of elements? I am very new to JMeter and hence, expect a little elaborated answer. :)

Upvotes: 0

Views: 938

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

The fastest and the easiest way is using __chooseRandom() function available via JMeter Plugins. The relevant configuration of the HTTP Request Sampler would be:

  • Path: /${__chooseRandom(add,sub,mul,div,path)} - get a random option and store it into ${path} JMeter Variable
  • Name: ${path} - change HTTP Request Sampler Label (for separate reporting)

ChooseRandom

You can install __chooseRandom() and other plugins Functions via JMeter Plugins Manager from the "Available Plugins" tab:

Custom Functions Plugins manager


Be aware that your requests will be random hence your test scenario won't be repeatable so I would recommend considering using other test elements instead i.e. Throughput Controller or Switch Controller or Weighted Switch Controller.

See Running JMeter Samplers with Defined Percentage Probability article for above test elements configuration details.

Upvotes: 3

Related Questions