Home > Software engineering >  JMeter: How to send multiple unique json body?
JMeter: How to send multiple unique json body?

Time:09-22

I have written a REST API and now my requirement is to load test it for 1k calls or something. Problem is the request json has an unique attribute - Cnumber which needs to be changed for every request.

json request:

{ "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "C7" }

how can I make this request for 1K users concurrently with Cnumber changes in every request?

CodePudding user response:

Depending on what you're trying to achieve:

  1. Incrementing number can be generated using __counter() function like:

    { "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "${__counter(FALSE,)}" }
    
  2. Random number can be generated using __Random() function

    { "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "${__Random(1,2147483647,)}" }
    
  3. Random alphanumeric string can be generated using __RandomString() function like:

    { "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "${__RandomString(2,abcdefjhijklmnopqrstuvwxyz0123456789,)}" }
    
  4. Current thread number: __threadNum() function

    { "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "${__threadNum}" }
    
  5. GUID-like structure: __UUID() function

    { "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "${__UUID}" }
    

More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

CodePudding user response:

You could use a timestamp...

{ "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "C${__time}" }

Cnumber with timestamp example image

  • Related