DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Implementing DDoS With MuleSoft: Demonstration With Apache JMeter
  • Mastering Redirects With Cloudflare Bulk Redirects
  • A General Overview of TCPCopy Architecture
  • Address Non-Functional Requirements: How To Improve Performance

Trending

  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  • Issue and Present Verifiable Credentials With Spring Boot and Android
  • The 4 R’s of Pipeline Reliability: Designing Data Systems That Last
  • Java Virtual Threads and Scaling
  1. DZone
  2. Data Engineering
  3. Data
  4. JMeter Parameterization: The Complete Guide

JMeter Parameterization: The Complete Guide

If you're wondering about how to parameterize your scripts in JMeter, then this is the resource for you. Come have a look!

By 
Yuri Bushnev user avatar
Yuri Bushnev
·
Feb. 14, 18 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
38.9K Views

Join the DZone community and get the full member experience.

Join For Free

Parameterization is the act of creating different data sets for different users in the same test script. For example, running multiple users with different credentials in the same script. This makes it one of the main aspects in performance tests creation.

In Apache JMeter, one of the common ways to parametrize your performance scripts is to use a CSV file. The best example of CSV input files usage is a login process. If you want to test your application across different users, you need to provide a list of user credentials.

Let’s assume that we have a login request that works for one specific user:

Increase imagejmeter parameterization

We can easily parametrize that request by using an external CSV file and running the script across different users. To add the CSV parameterization config:

Right click on login request -> Add -> Config Element -> CSV Data Set Config

Increase imageload testing parameterization

A short explanation of "CSV Data Set Config" parameters:

  • Name - element name as it will be used in the JMeter tree
  • Filename - name of the input file. Relative file names are resolved based on the path of the active test plan. Absolute filenames are also supported
  • File Encoding - encoding of input file, if it’s not the platform default
  • Variable Names - list of separated variable names that will be used as a container for parsed values. If empty, the first line of the file will be interpreted as the list of variable names
  • Delimiter - delimiter that will be used to split the parsed values from the input file
  • Allow quoted data? - "True," in case you want to ignore double quotes and allow such elements to contain a delimiter.
  • Recycle on EOF? - "True," in case the file test plan should iterate over the file more than once. It will instruct JMeter to move the cursor at the beginning of the file
  • Stop thread on EOF? - "False," in case of loop iteration over the CDC file and true if you want to stop the thread after reading the whole file
  • Sharing mode-
    • All threads - the file is shared between all virtual users (the default)
    • Current thread group - the file will be opened once for each thread group
    • Current thread - each file will be opened separately for each of threads
    • Identifier - all threads sharing the same identifier also share the same file

 

Let’s create a csv file containing different users with names and passwords:

Increase imageperformance testing parameterization

We can now use this file with the CSV Data Set config. In our case, it’s enough to add the “Filename” and “Variables Names” config values:

Increase imageworking with parameters in jmeter

The last step we have to take is to parametrize the login request with CSV variables. This can be done by substituting the initial values with appropriate variables from the “Variable Names” configuration field of the CSV Data Set Config, like this:

Increase imagejmeter parameters - a guide

If we run our test script now, JMeter will substitute these variables with values from the "TestUsers.csv" file. Each JMeter virtual user will receive credentials from the following csv file line.

The login request by the first user:

Increase imagea guide to jmeter parameterization

The login request by the second user:

Increase imagejmeter parameterization tutorial

JMeter Parameterization Using Databases

Another way to parametrize your performance scripts is to use database data through JDBC. JDBC is an application programming interface that defines how a client can access a database.

First of all, download the relevant JDBC driver to your database. For example, the mysql driver can be found here. Then, you need to add the .jar file to the test-plan by using the form below:

Increase imagehow to parameterize your load tests

After that, configure the database connection by using the "JDBC Connection Configuration" element. Like this:

Right click on Thread Group -> Add -> Config Element -> JDBC Connection Configuration

Increase imageload testing with parameters

"JDBC Connection Configuration" parameters:

  • Name - name of the connection configuration that will be shown in the thread group tree
  • Variable Name - name that will be used as unique identifier for the db connection (multiple connections can be used and each one will be tied to a different name)
  • Max Number of Connections - maximum number of connections allowed in the connection pool. In case of 0, each thread will get its own pool with a single connection in it
  • Max Wait (ms) - pool throws an error if the specified timeout is exceeded during db connection
  • Time Between Eviction Runs (ms) - number of milliseconds to pause between runs of the thread that evicts unused connections from the db pool
  • Auto Commit - yes to turn auto commit for related db connections
  • Test While Idle - check idle connections before an effective request is detected. More details: BasicDataSource.html#getTestWhileIdle
  • Soft Min Evictable Idle Time(ms) - period of time during which a specified connection might be idle in the db pool before it can be evicted. More details: BasicDataSource.html#getSoftMinEvictableIdleTimeMillis
  • Validation Query - healthcheck query that will be used to verify if the database is still responding
  • Database URL - JDBC connection string for the database. See here for examples
  • JDBC Driver class - appropriate name of driver class (specific for each db). For example, ‘com.mysql.jdbc.Driver’ for MySql db
  • Username - database username
  • Password - database password (will be stored unencrypted in the test plan)

In our case we need to setup the mandatory fields only:

  • Variable name Bound to Pool
  • Database URL
  • JDBC Driver class
  • Username
  • Password

The rest of the fields in the screen can be left as defaults:

Increase imageconfiguring jmeter parameterization

Let’s assume that we stored test user credentials in the database:

Increase imagejmeter load testing with parameters - learn how

Now when the database connection is configured, we can add the JDBC request itself and use its query to get all the credentials from database:

Right click on Thread Group -> Add -> Sample -> JDBC Request

By using the "Select Statement" query and "Variable Names" we can parse the response to custom variables.

Increase imagehow to run performance tests with jmeter with parameters

We will now have JMeter variables that can be used further in subsequent requests. Specified variables will be created with incremental suffix (email_1, email_2, email_3…..).

To use these variables in the "Login request", we need to add a counter that will be used to access the right values from the JDBC query response. To add the "Counter" element in JMeter:

Right click on Thread Group -> Add -> Config Element -> Counter

Increase imagejmeter parameterization configuration

After that, we can update the "Login request" using the __V function. This returns the result of evaluating a variable name expression and can be used to evaluate nested variable references:

Increase imagejmeter open source load testing with parameters

The specified configuration is enough to use database values to run the script across different users:

Increase imagejmeter parameterization

 

If you need to execute a repeating sequence of the same action with different parameters, you can use the "Parameterized Controller" plugin. Let’s assume that we want to parameterize the login workflow:

Increase imageworking with jmeter parameters

First of all, you need to install the "Parameterized Controller" plugin as it is not included into the JMeter core. Installation steps of that process can be found here.

Let’s move the "Login Request" into a separate controller and disable it (right-click it and select "Disable"). This is the most preferable way to have a modules container inside your test plan and avoid using Workbench as such a container.

After the installation is over, you can add two "Parameterized Controller" controllers with different user credentials:

Right click on Thread Group -> Add -> Logic Controller -> Parameterized Controller

Increase imageparameterizing jmeter's login workflow

Parameterized Controllers contains the "User Defined Variables" section, where you can specify your parameters. Put the credentials of the first user in the first parameterized controller and the second user credentials in the second parameterized controller.

Increase imagejmeter's parameterized controller

Inside both parameterized controllers, add references to the "Reusable Controller" to call the "Login request" with different parameters. It can be done this way:

Right click on "Parameterized Controller" -> "Add" -> "Logic Controller" -> "Module Controller"

Increase imageusing jmeter's parameterized controller

When running your script, you will see that the "Login request" triggered each of the parameterized controllers separately. It can be very useful in case you need to run your script across different combinations of input parameters.

Increase imageparameterization load testing

That’s it! You now know a number of ways to parameterize your tests. To learn more tips and hacks for building your JMeter scripts, try out our free JMeter academy.

Try out BlazeMeter, which enhances JMeter features. Request a demo, or put your URL in the box below and your test will start in minutes.

Database connection Requests Testing Data set CSV Test plan Java Database Connectivity

Published at DZone with permission of Yuri Bushnev, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Implementing DDoS With MuleSoft: Demonstration With Apache JMeter
  • Mastering Redirects With Cloudflare Bulk Redirects
  • A General Overview of TCPCopy Architecture
  • Address Non-Functional Requirements: How To Improve Performance

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!