When designing a load test, it is a common goal to emulate real-world requests to the best extent possible. It is easy to generate thousands of requests with JMeter. However, there is often a need to generate many different requests. Using parameterization, this is a straightforward task. In this brief post, we will illustrate the steps of parameterizing your JMeter tests from a CSV data source.
Step 1.
The first element we want to add to our test plan is a “CSV Data Set Config”. We can add this directly at the root level of the Test Plan:
Step 2.
Once added, we can configure the CSV data source. The filename is the only field that is usually required. However, if our CSV file does not contain a header row, we can specify a comma-delimited list of column names. Correspondingly, the column names in either case will become variable names when referenced within our test.
Step 3.
The next logical step would be to use data fields from our CSV file to create variable requests. JMeter has a special convention for this – ${variable}. (This syntax is explained here in the JMeter documentation under “User Variables”.) An example of such usage in an “HTTP Request” element would be as follows:
In the above screenshot we have the request parameter “itemCode” configured to the value contained in “columnX” within our CSV file. For each iteration where this request is called, it will read the value from sequential lines within that file.
Step 4.
Once we complete the test plan, it is time to upload it to RedLine13. However, since our test plan is dependent on a CSV file, we’ll have to upload that as well. The CSV file (in this case “Sample CSV File.csv”) is added to the test run as an “Extra File”:
Running the Test
So, what happens now when we run our test? If we configured everything properly as above, we should see requests come through with parameters set to match what is contained within our CSV file. Here is an example of what we can expect to see with a “View Results Tree” listener configured:
Each sequential request that references the CSV-mapped variable will read from the subsequent line. If you execute more requests than you have lines in your CSV file, JMeter will cycle to the beginning of the file and reuse values again.
Advanced Data Driven Tests
Like what you see and ready to move to the next level with data driven JMeter testing on RedLine13? We have a feature on our platform that lets you split records in CSV across your load agents which you can read about here. Another advanced concept we have written about is using Groovy scripting for data driven testing using Excel files.
Ready to try this example out for yourself? We offer a full-featured free trial that you can sign up for and start testing today!