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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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

4 Things You Should Never Do With Your JMeter Scripts

Making sure you don’t do these things will ensure your tests run smoothly and will save you from the eventual headache of trying to decipher an unreadable script.

Federico Toledo user avatar by
Federico Toledo
·
Mar. 22, 17 · Opinion
Like (3)
Save
Tweet
Share
8.14K Views

Join the DZone community and get the full member experience.

Join For Free

Your JMeter scripts are complete and you’re ready to run them in JMeter or in BlazeMeter. All set, right? Hold on. Before you click "start," here are four tips and best practices for things you shouldn’t do with your JMeter script.

Making sure you don’t do these four things will ensure your tests run as smoothly as possible and will save you from the eventual headache of trying to decipher an unreadable script. More importantly, if you don’t do these four things, you’ll be able to have more confidence in the results, without saturating the load generators.

1. Don’t Make Your Script Too Heavy

Your script should be light. So don’t add an exaggerated amount of validations, logic, response parses, debuggers login information, etc., that will just weigh down the script. Otherwise, you won’t be able to execute much load on a machine without saturating its resources, a situation to avoid in order to obtain trustworthy results.

The same happens when you enable too many listeners because they collect a lot of data and render the information in real time which is very resource consuming. Try to avoid this, and do so even more when you plan to use Blazemeter to run your performance tests.

2. Don’t Run the Script Exactly as You Recorded It 

After recording your script, there is still some work to do before you run it. It’s necessary to correlate variables, parameterize, and add elements to faithfully simulate users.

Here is a short list of general samplers and modifications that you’ll need to consider:

  • Add a cookie manager. Pay attention whether you need to erase the cookies on each iteration or not (you can set this with a checkbox in the sampler).
  • Add an HTTP request default sampler to define the server, port, and protocol in just one place. If you erase this specification from your requests, you will be able to change your test environment easier.
  • Review which response assertions you need to add.
  • Parametrize hosts in the headers to make your script more flexible and supportable.

There may be other samplers that you need to add depending on your scripts like Cache Manager, counters, regular expressions, Authoritation Managers, or CSV Data Set Config (if you need to read a data file). All of these actions will help you to develop your script in a way that simulates real user actions, which is critical for obtaining reasonable results.

3. Don’t Include Absolute File Paths

Always use a relative path that allows you to run the script from other machines without having to modify it, especially when you need to work with data files. It’s not practical to change the path of your files each time you want to change your workspace. By adding relative paths, you are able to save time later on. This is possible because relative file names are resolved in JMeter according to the active test plan’s path. So make sure CSV files are stored in the relative directory JMeter starts from.

Here is an example of an absolute path setting (the incorrect way):

Image title

And now, here is how to do it the recommended way:

Image title

In addition, if you are planning to run your test in BlazeMeter, you won’t need to add a path to your file path specifications, but rather only specify the file name. BlazeMeter understands that the data file is in the same directory as your script.

4. Don’t Leave URLs That Don’t Actually Matter to You

After recording your script, you might find some URLs in it that were generated by the browser, like Google Analytics, certain plugins, Windows Update, etc. These make your script less readable and more heavy (because the script will generate more requests) without adding any value to the test. So, verify each request you include in your script and check that the host you are addressing is part of your SUT (system under test). If not, just erase them. Focus only on measuring the performance of servers that you are interested in.

Let’s look at this example of an external URL in a test. Suppose we are testing Abstracta’s servers (this is my company so please do not try this at home!). This means I would be interested in the host, www.abstracta.us.

Here’s what it would look like:

Image title

But in our just recorded test plan, we see this URL belonging to an external server — www.youtube.com:

Image title

We are not interested in testing YouTube's servers, so we need to erase this request and any others like this one, in order to develop a script that is much more readable.

We’re interested in hearing your tips for writing JMeter scripts! Please share in the comments section below.

Data file Testing

Published at DZone with permission of Federico Toledo, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Spring Cloud: How To Deal With Microservice Configuration (Part 1)
  • How To Use Terraform to Provision an AWS EC2 Instance
  • Streamlining Your Workflow With the Jenkins HTTP Request Plugin: A Guide to Replacing CURL in Scripts
  • Automated Performance Testing With ArgoCD and Iter8

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: