Site icon Vinsguru

JMeter – Continuous Performance Testing – JMeter + ANT + Jenkins Integration – Part 1

Goal:

To create a Continuous Delivery Pipeline which includes Performance Testing process to detect any performance related issues as early as possible.

 

Usually the full scale Performance Test will be done in the Staging/Pre-Production environment which could be identical to your Production environment. Code push to Staging happens after thorough QA functional/regression verification is done. So even if QA certifies the build, there is a chance that code might not work as expected at certain load which could be found only in Staging environment. This performance issue requires code change -> build -> QA verification once again which could postpone your Production push!

So, Can we fit the performance testing into the existing continuous development & testing process to detect the performance issues as early as possible?

Yes! We absolutely can! The idea here is to run the performance test in the lower environments [Dev/QA] (we might have to adjust the load accordingly) & to compare the results against some baseline metrics. Note that this is NOT going to replace the full scale performance test which we will do in the Staging environment.

Lets see how we can implement the above process in this post by using JMeter + Ant + Jenkins.

Create Performance Test Script:

  1. Create some basic performance test script using JMeter.
  2. Check below useful articles from TestAutomationGuru.
    1. Creating Modular JMeter Test Scripts.
    2. Ensure that the script can be run on any given environment like QA/PPE/Staging etc. [Check here]
  3. I am going to consider a simple JMeter test which will login, search for a product and logout.
    1. I have used variables in the Thread Count, Ramp Up and Duration fields.
    2. At run time, we will pass values for those variables from Jenkins.
    3. To run the test in design mode/standalone mode, We use User Defined Variables as shown here. So, it takes the default values (like 1 user with 1 second ramp-up for 5 seconds test duration).
  4. Ensure that the scripts runs fine.

                         

 

Running JMeter test using ANT:

ANT: It is a build tool – here we will be using ANT to execute a set of tasks in the given order. For ex:

You would be calling these tasks once you are done with the build and unit/integration tests.

Install ANT:

  1. Download Ant from here.
  2. Uncompress the downloaded file into a directory.
  3. Set environmental variables
    • JAVA_HOME to your Java environment
    • ANT_HOME to the directory you uncompressed Ant
    • Add ${ANT_HOME}/bin (Unix) or %ANT_HOME%/bin (Windows) to your PATH.
    • If you do not have a JMETER_HOME variable, please set that too. It should point to the JMeter folder where you see ‘bin’
  4. In the cmd prompt/terminal, type ant and enter as given below. You should see below message (The system should know that there is an ‘ant’ command)

Create ANT-JMeter Project:

Now we are going to create an ANT project as given below.  [I have shared this sample project in GitHub]

test folder is going to contain your .jmx file

lib folder will have all the libs required for ant-jmeter task + any other libs you want to include for your jmeter test.

function folder will have all the beanshell scripts for your test.

build.properties A property file which is going to pass the values for JMeter UDV.

ANT Build file:

This is an important part. Ant needs a build.xml file (it does not have to be ‘build.xml’ – but that is a default name ant will expect) where you have all the tasks defined.
Lets create a build.xml file as given below. [I have shared this sample project in GitHub]

We have 3 targets here.

Now in the command prompt/terminal, go to the project folder and type ‘ant show-test-properties‘. You should see below output.

ANT: Run JMeter Test:

Lets run the test by issuing command:

ant run

Now we can see we have the log and result files created.

 

 

 

Creating HTML Report:

Run below command to generate the HTML report under output folder

ant generate-report

ant console log:

Report:

 

 

Creating Charts:

 

The above HTML file itself has nice charts. However you still might want to create charts through command-line to send via emails/slack etc.

To create charts, we need few external plugins.

Run below command to install the required plugins.

ant install-plugins

Once plugins are installed, Generate charts by issuing command:

ant generate-charts

Once the job is complete, We can see all the charts we wanted are generated and placed under the result folder.

 

ANT – Running all tasks sequentially:

Run all ant tasks by issuing a command: ant all

 

Sample Project:

Having Issues?

ant -v run

 

Summary:

Now we will be able to run our JMeter test by passing the test properties from a property file through ANT. We also have automated creating HTML file and creating charts from the result file.

We will see how to invoke this test from Jenkins in the next post.

 

Thanks to [Ref: http://www.programmerplanet.org/projects/jmeter-ant-task/]

 

 

 

 

 

 

Share This:

Exit mobile version