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

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • C# Applications Vulnerability Cheatsheet
  • Best Performance Practices for Hibernate 5 and Spring Boot 2 (Part 4)
  • Resolving Parameter Sensitivity With Parameter Sensitive Plan Optimization in SQL Server 2022
  • Useful System Table Queries in Relational Databases

Trending

  • Exploring Intercooler.js: Simplify AJAX With HTML Attributes
  • Is Low Code the Developer's Ally or Replacement? Debunking Myths and Misconceptions
  • Simplifying Multi-LLM Integration With KubeMQ
  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 1
  1. DZone
  2. Data Engineering
  3. Databases
  4. How to Create Test Data in a Database With JMeter

How to Create Test Data in a Database With JMeter

Occasionally, the test data in a database isn't enough and testers must create more. Learn how to use JMeter to create, modify, and delete data from a database.

By 
Sergey Horban user avatar
Sergey Horban
·
Feb. 07, 18 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
14.9K Views

Join the DZone community and get the full member experience.

Join For Free

When performance testing APIs, you sometimes have to use different test data than what is present in the database. Occasionally, the test data in the database is not enough and the testers must create more themselves. Apache JMeter™ is very suitable for these purposes because it allows you to create, modify, and delete data from a database. This post will explain how.

In order to add data to the database, you need to do the following.

Configure the connection to the database as described here. In  JDBC Request, set the following:

Example code:

INSERT INTO `sakila`.`city`(`city_id`,`city`,`country_id`,`last_update`)
VALUES(603,'New York','103',null)

This is a SQL query that adds the specified data to the city table:

  • `sakila`.`city`: sakila is the name of the database.
  • city is the name of the table that exists in the sakila database.
  • `city_id`,`city`,`country_id`,`last_update` are the names of the fields that contain the city table.
  • 603,'New York','103',null are the values that we add to the table. If we need to add other values, then we only need to replace these values with the others.

Next, go to Thread Group > Add > Listener > View Results Tree.

View Results Tree displays the sent requests and the received responses. In our case, this element allows us to see the query being sent to the database and the response received from the database.

After starting our request to add data to the database, in View Results Tree, we will see the request itself, as shown in the image below.

The result of the successful addition of data will be as shown in the image below. The successful result of adding data to the table is when the response contains a row of 1 updates. 1 updates means that one row is added to the table.

In the database itself, our added data will look like this:

When specific test data already exists in the database but is partially not suitable for the test case, it makes no sense to add new test data. You can simply change the existing.

For example, above, we added new data to the database. If this data is suitable for the test but only with a different value of city_id, then you can do the following:

In JDBC Request, set the following:

Example code:

update `sakila`.`city` 
set city_id = 7000 
where city_id = 603

This is a SQL query that changes the value of column city_id = 603 to city_id = 7000 in the city table.

After starting our request to updating data to the database, in View Results Tree, we will see the request itself, as shown in the image below.

The result of the successful data change will look like this:

In the database itself, our modified data will appear:

If we need to delete the test data from the database after the test, you can do the following:

In the JDBC Request, set the following:

Example code:

delete 
from `sakila`.`city`  
where city_id = 7000

This is a SQL query that deletes from the table city the row that has the value of the column city_id = 7000.

After starting our request to delete data in the database, in View Results Tree, we will see the request itself, as shown in the image below.

The result of successful data deletion will be shown like this:

When you have to regularly create test data in specific tables by using different SQL queries, then in the JDBC Request you can use a variable to replace the SQL query itself.

In order to use a variable in a JDBC Request, you need to set up the database, and then do the following.

Do Thread Group > Add > Config Element > User Defined Variables.

In User Defined Variables, add the following:

  • insert_city is the name of the variable that will be used in the JDBC Request.

  • INSERT INTO `sakila` .`city` (` city_id`, `city`,` country_id`, `last_update`) VALUES (603, 'New York', '103', null) is the value of the variable insert_city.

In the JDBC Request, set the following:

Example code:

${insert_city

This is a syntax that allows you to use a variable created in User Defined Variables.

After starting our request that adds data to the database, in the View Results Tree we will see the request itself, as shown in the image below.

The result of the successful addition of data will be as shown in the image below:

In the database itself, our added data will look like this:

The SQL query that resides in the JDBC Request can also contain variables.

To do this, you need to do the following.

Thread Group > Add > Config Element > User Defined Variables. In User Defined Variables, add the following

The variables added in the image above will be used in the query to add data to the database.

In JDBC Request, set the following:

Example code:

INSERT INTO `sakila`.`city`(`city_id`,`city`,`country_id`,`last_update`)
VALUES(${city_id},'${city}','${country_id}',${last_update})

This is a SQL query that adds data to the city table.

$ {city_id}, $ {city} ',' $ {country_id} ', $ {last_update} is a syntax that allows you to use variables created in User Defined Variables.

After starting our request to add data to the database, in View Results Tree, we will see the request itself, as shown in the image below.

The result of the successful addition of data will be as shown in the image below.

In the database itself, our added data will look as shown in the image below.

That's it! You now know how to create test data in a database by using JMeter. To learn more JMeter, check out our free JMeter academy.

Database Test data Requests sql

Published at DZone with permission of Sergey Horban, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • C# Applications Vulnerability Cheatsheet
  • Best Performance Practices for Hibernate 5 and Spring Boot 2 (Part 4)
  • Resolving Parameter Sensitivity With Parameter Sensitive Plan Optimization in SQL Server 2022
  • Useful System Table Queries in Relational Databases

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!