How to Work With CSV Files in JMeter
These tips will help you effectively work with CSV files in JMeter when running performance testing.
Join the DZone community and get the full member experience.Join For Free
One of the most common challenges in every test project is the test data management. Data is typically spread across multiple databases in today’s business world and it’s hard to manage its complexity. Working with clean data is crucial when it comes to performance testing however realistic and reliable data is hard to create.
Before you start performance testing, you should consider how to maintain the data. Performance tests are very challenging since you simulate thousands of users on your application. It requires you to consume so much data in a short period of time. It’s very hard to revert the data to its old state when you need it. So you need to come up with a good strategy to handle the data successfully.
One other thing to consider in a performance test project is the caching mechanism. When you run a test with the same data, there’s a good chance that the app will start to cache the response. So your request won’t reach the server. For this reason, we can conclude that you need a variety of data.
JMeter lets you deal with data by using CSV files. Here are some tips about CSV usages;
#1 — Try to Use the Data as Dynamic as Possible
Browsing a website, filtering data in a website are good examples. Your data is on a website or an application, you just need to use this data by using your CSS or JQuery Extractors as told in this article (https://loadium.com/using-css-selectors-in-jmeter-scripts/) and randomize your actions. If you have a pagination, determine how many pages you have and try to navigate the last ones. You will definitely bypass the caching mechanism.
#2 — Be Very Careful About Your Iteration and Data Structure
Assume you have a very strict flow as below and you add a CSV Data Set Config to it. JMeter will only run the first line of the CSV file even if you have thousands of iteration in your Thread Group.
Why? Because JMeter opens the file every time a new iteration starts. That’s why only the first line will be used in your test. So you need to loop through the file as below. Therefore, during the test runs, JMeter opens the file and iterates through the data. Request of consuming the data will execute different parameters.
#3 — CSV Configuration
Your CSV Config has three configurations in it.
Recycle on EOF: In case it’s set to true when JMeter reaches the end of the file, it will go to the beginning and iterate the CSV file.
Stop Thread on EOF: Thread will stop its execution when JMeter reaches the end of the file. In case you have 20 iterations in a loop and 10 lines of data, JMeter will stop the execution at 10th request. So it will override the iteration number.
Sharing Mode: According to the configuration, you decide whether or not to allow other Thread Groups to use the CSV file.
All these tips will be handy for your test execution. Happy performance testing!
Published at DZone with permission of Can Ho, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.