JMeter – Parameterization (CSV Data Set Config)
Each non-functional test has a standard requirement for the test data format. Performance tests simulate the scenario in real time using large and clear amounts of test data. You need to generate or get the test data from the server log. Now how can I use external test data with Apache JMeter for non-functional testing? Also, how does Apache JMeter handle parameterization? You can use CSV or text-based external test data sets with Apache JMeter thanks to a built-in element. The ‘CSV Data Set Config’ element is named like this.
CSV Dataset Configuration Element: What is it?
Use the “CSV Dataset Settings” item to read lines from a file and split them into variables. It is useful for testing with random and different values and is well-suited for handling a large number of variables.
How do I add and use the ‘CSV Data Set Config’ element?
As you do the following:
- Choose the ‘Test Plan’ or ‘Thread Group’ node (where you want to add the ‘CSV Data Set Config’ element).
- The CSV Data Set Config element is particular to a given scope. Its reach is limited to that thread group when added under a thread group rather than under “Test Plan,” which grants it a global scope.
- Right-click on the ‘Test Plan’ or ‘Thread Group’ node
- Mouse hover ‘Add’
- Mouse hover ‘Config Element’
- Click ‘CSV Data Set Config’
- In the ‘Filename’ field, enter the location of the.csv file (Test Data file).
- Note that JMeter can only use test data that is stored in .csv file format. A.csv file is a comma-separated file in which each row of values in the file is separated by a comma. Every value is considered to be a value of a specific variable.
- Set the remaining option as per the requirement
What qualities does the ‘CSV Data Set Config element have?
The following qualities apply to “CSV Data Set Config”:
1. To specify the name “CSV Dataset Configuration”.
2. Comments: Please leave any comments you have.
3. Filename: The full or partial name of the file being read. Specify the full path along with the file name if the files are not in the Apache JMeter bin folder; otherwise, just the name (with extension) is sufficient. When resolving relative filenames, the current test plan path is taken into account. The CSV file should be kept on the server host system in the appropriate relative directory where the JMeter server for distributed testing is started. Absolute filenames are also supported but note that unless the remote server has the same directory structure, they probably won’t work in remote mode. When a physical file is referenced in two different places, such as csvdata.txt and ./csvdata.txt, those references are treated as two separate references.
4. File Encryption: If the platform’s default encryption is not adequate, use it to read the file.
5. Variable names (separated by commas): names of variables in a list, separated by commas. JMeter reads the first line of the file and treats it as a list of column names if the variable name field is left blank. The delimiter must be used to separate the names. Double quotes can be used to refer to it.
6. Separator: You can use “t” or “,” as a separator. the character to use as the separator to split the records in the file. The remaining variables are not updated if there are fewer values on a line than there are variables, so they keep their previous value, if any.
7. Allow enumerated data? Can you quote values in the CSV file? Values can be surrounded by “” (double quotes) if this option is enabled (True), allowing values to have a separator character.
8. Recycle at EOF: When a file reaches the end (EOF), it will be read back from the beginning. True is the default setting.
EOF thread stopper: If the thread reaches the end of the file (EOF), this option terminates it. False is the default setting.
When the file reaches the end, all variables are set to the values of the last line 9. if “Recycle on EOF” and “Stop Thread on EOF” are false. When a file reaches the end, the thread will stop if “Recycle on EOF” is set to false and “Stop Thread on EOF” is set to true.
There are four different sharing modes available.
10. All Threads: Each thread can access the same file. This is the default setting.
Each file is opened once for each thread group that contains the element, regardless of the current thread group.
Each file is opened independently by each thread in the current thread.
Edit: The same file is shared by all threads with the same identity. For example, if you have four thread pools, you can use a common ID for two or more of the thread pools to share the file. Alternatively, you can use the thread number to distribute the file to threads of the same number in other thread pools.
Parameterization Example
Additional Points:
Typically, the CSV dataset configuration element is added to the test plan to use the parameter value globally. If you have more than one thread pool with a different CSV file, you must add the CSV dataset configuration element on the corresponding thread pool or create a file pool, one for each thread.
By default, the file is opened only once, and each thread uses a different line than the file (when sharing mode is All Threads). However, the order in which the rules are passed to the threads depends on the order in which they are executed, which can vary between iterations. The rules are read at the beginning of each test iteration. The filename and mode are resolved on the first iteration.