5 Tips to Turn Recorded JMeter Scripts into Reusable Tests
Load and performance issues can be difficult to resolve when found late in the software development lifecycle, yet teams still often wait until the last minute to performance test their applications. This can be costly, especially if the problem ends up being an issue with the overall architecture of the application.
Load and performance testing should be treated the same as all other types of software testing and be executed early and often.
Developing these tests as early as possible and executing them as part of a CI/CD pipeline can help:
- Determine if the overall architecture has load or performance problems that need to be addressed
- Reduce the time it takes to fix load and performance issues by addressing the issue when it’s introduced
- Ensure the load and performance testing framework is in place and working
Using an open source tool like JMeter to create, manage, and execute load and performance tests while the code is being developed is an inexpensive way to help find issues.
JMeter’s HTTP/HTTPS recording template is a quick and easy way to get started, allowing testers to record their steps while manually clicking through the application. The actual test is created when the user begins recording, and each action the user takes becomes a request within the test.
While this is a great place to start, these tests will need some work before they can be considered good load or performance tests.
Here are five suggestions to help turn your recorded scripts into quality reusable tests.
Use Variables
A recorded script will have hard-coded values in URLs or parameters. Tests using hard-coded values are not guaranteed to run successfully more than once, if at all. Tests should be self-contained and not dependent on external data. Using a JMeter post processor to extract data from a server response will allow for the creation of variables, which helps keep tests self-contained and running smoothly.
Parameterize Values
Use data sets to parameterize the hard-coded parameters and allow multiple users to execute the same test with different data. This helps to simulate how the application will actually be used instead of testing the same data with the same user every time the test is executed.
Update Thread Group Values
Update the thread group properties to increase the number of concurrent users, the ramp-up time for those users, and the number of times each user will loop through the script.
Add Timers
By default, JMeter will execute the steps of each test as fast as possible. Adding random time constraints helps to simulate how different users react when using the application by adjusting the “think time” spent on each page.
Rename Samplers
When running several tests in parallel, it can be difficult to determine which test or which step in the test may be failing if you use a poor naming convention. Modifying test names and component names can be very helpful when trying to debug an issue or determine which tests are running or failing.
Bob Foster is presenting the session Finding Performance Issues Early with JMeter at STARWEST 2019, September 29–October 4 in Anaheim, California.