Skip to main content
Blog General

Performance Testing of Ecommerce Sites With JUnit & JMeter

Kannathasan E
May 30, 2016 |

Performance is everything for an E-commerce site. Just a delay of about 250 milliseconds of a page load time, is what keeps your customer going to your competitor. Before we get into the details of performance testing of E-commerce sites with JUnit &Jmeter , it is important to understand why performance testing?

For an E-commerce website performance is very important. Performance tests reveal how an eCommerce site behaves and responds during various situations. There are some specific tests that need to be executed in order to find potential bottlenecks and improve the performance of the sites. One such test is the performance testing of eCommerce sites with JUnit & JMeter.

Performance Testing of Ecommerce Sites With JUnit & JMeter

By reusing the JUnit scripts in JMeter it is possible to do performance testing in an easy and efficient manner.

In general, the QA team automates eCommerce site using selenium so that we can reuse the same scripts to do the performance testing too. By this, we can save the script writing time and also reduce the performance testing cycle time.
Integration of JMeter with JUnit code

  1. Create a JUnit Test Project
  2. Create Jar for the JUnit Project
  3. Put Jar in JMeter’s lib/JUnit directory
  4. Run JUnit tests in Jmeter
Flow diagram – JUnit to JMeter


  Steps to be followed
  • Create a JUnit Test Project

Create the Java project using JUnit annotations

  • Create Jar for the JUnit Project

To export jar files, right click on the Project folder -> Select Export-> Expand Java folder -> Click on Jar files -> Click Next -> -> Select the Resource to export -> Check the option “Export Java source files and resources” ->Select the export destination -> Finish

  • Adding Jar files in JMeter’s lib/JUnit directory

Next add the generated Jar file in the JMeter’s lib/JUnit directory and restart JMeter

  • Running JUnit tests in JMeter

1. Open JMeter and create a “Thread Group”

Right click on the Test Plan -> Select Add – > Select Thread (Users) -> Select Thread Group

2. Create a “JUnit Request”

Right click on Thread Group -> Select Add -> Select Sampler -> Select JUnit Request.

3. Check the “Search for JUnit 4 annotations (instead of Junit3)”check box

4. Select the JMeter Classname & Testmethod in the JUnit Request component.

5.Add a listener

Right click on Thread Group -> Select Add -> Select Listener (One can select the type of listener as desired , say “View Results in Table”/ “View Results in Tree”/”Summary Report”


6.Save the Thread Group Test Script files to .jmx format & start the execution in JMeter.

7.The time taken by each sampler could be noted from the results shown in “View Results in Table” and the Standard Deviation, Throughput, Mean, Average, Minimum Maximum time the samples took to execute could be noted from the “Summary”/”Aggregate” reports


Sample JUnit Code

Sites that load fastest have a competitive advantage. Since everything on the internet is just a click away, it is vital to have quick load times to keep customers on your site and not your competitor’s. When it comes to eCommerce sites, even a few minutes of downtime can be extremely costly and can become big news. Performance testing with JMeter and JUnit ensures smooth running of eCommerce sites.


Kannathasan E

Kannathasan is a Certified Tester (Foundation level ). He loves testing eCommerce applications and ferreting out hidden bugs. Likes solving challenging puzzles during his free time.

More posts by Kannathasan E