avatarTanmay Deshpande

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3166

Abstract

get a detailed report, you can run the test plan using the JMeter command-line utility:</p><div id="15b0"><pre>jmeter -<span class="hljs-built_in">n</span> -<span class="hljs-built_in">t</span> APITestPlan.jmx -l result.txt -e -o reports/</pre></div><p id="076b">Here <code>APITestPlan.jmx</code> is the test plan I created in the previous step. <code>result.txt</code>is the file in which test results will be stored, and <code>reports</code> is the folder in which the HTML reports will be created. If you open the <code>reports/index.html</code> page, you will be shown very intuitive results:</p><figure id="5d36"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*WubaRJCmg8CxQ6GKdsh2_g.png"><figcaption></figcaption></figure><p id="591a">You can add complexity to your tests as per business needs.</p><h1 id="0e5f">Taurus</h1><p id="91ee"><a href="https://gettaurus.org/kb/Index/">Taurus</a> is an open-source automation framework for running various open-source load-testing tools and functional-testing tools. For regular automated test runs, you need only stick to using Apache JMeter. But if you plan to do continuous testing, then you need to use a tool like Taurus that runs the load tests and produce results in a common format like JUnit results.</p><p id="43f3">Installing Taurus is easy. You can look at the details on the <a href="https://gettaurus.org/install/Installation/">installation page</a>.</p><div id="de05"><pre>pip <span class="hljs-keyword">install</span> --upgrade pip wheel pip <span class="hljs-keyword">install</span> bzt</pre></div><p id="acd4">Once the installation is done, you need to create a configuration file <code>taurus-config.yml</code>, as shown below:</p><figure id="ec91"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*ERv2DmEbb0f7eBURn9sB_Q.png"><figcaption><a href="https://gist.github.com/deshpandetanmay/436cf345667057ad5aead351a03b76d1">https://gist.github.com/deshpandetanmay/436cf345667057ad5aead351a03b76d1</a></figcaption></figure><p id="5f3e">In the above script, you need to give the path of the JMeter test plan. Here you need the report in the JUnit format so that you can use the test results and upload those to the DevOps platform. There are other reporting <a href="https://gettaurus.org/kb/Reporting/">options</a> also available in the Taurus that you may want to explore.</p><p id="295a">To check if everything is fine, you can run the Taurus command line, as shown below:</p><div id="e227"><pre><span class="hljs-keyword">bzt </span>taurus-<span class="hljs-built_in">config</span>.yml</pre></div><figure id="2c20"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*vrFqW8tXlc-as_m2mt5tFA.png"><figcaption></figcaption></figure><p id="ff7d">Post-run, you will be able to see the detailed reports on the command line, as shown below:</p><figure id="911d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*xEzYYBSNirQTwT8GvTH7zA.png"><figcaption></figcaption></figure><h1 id="f415">Integrate with Azure DevOps</h1><p id="8d98">Now that you are able to execute the tests on your PC/Laptop, it’s time to integrate these into the continuo

Options

us testing pipelines.</p><p id="227e">For this, you need to commit the Taurus config file as well as the Apache JMeter test plan file to a Git repo.</p><figure id="273d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*JPN-69wBEzKwvYQGRZHFxQ.png"><figcaption></figcaption></figure><p id="e5f3">Next, you need to create a pipeline, which consists of the following steps:</p><figure id="b9cb"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*laDPEvgvY50gNcbjo25p5g.png"><figcaption></figcaption></figure><p id="75b2">Here I am using the Azure DevOps hosted agent. If you are using your own agent, then you don’t need to install the pre-requisites on every pipeline run.</p><ol><li>Use Python — In this step, you are telling the agent that we need to use Python 3.x.</li><li>Install tools — In this step, you are installing the Python tools that will be useful for installing the other tools.</li></ol><div id="4265"><pre>python -m pip install <span class="hljs-comment">--upgrade pip setuptools wheel</span></pre></div><p id="d1ed">3. Install BZT — In this step, you are installing the Taurus tool.</p><div id="640c"><pre>pip <span class="hljs-keyword">install</span> bzt</pre></div><p id="df7a">4. Run load tests — In this step, you are running the actual load test and gathering results.</p><div id="7231"><pre>bzt loadtests/taurus-config.yml</pre></div><p id="8bd0">On a successful run, step 4 will produce an XML file in JUnit format.</p><p id="154c">Note that Taurus downloads the Apache JMeter binaries if not installed already.</p><p id="8dba">5. Publish test results — In this step, you are publishing the test results to the Azure DevOps test plan. Here you need to give the file name used for writing down the results in JUnit format.</p><h1 id="2d1e">Run the Pipeline</h1><p id="ce08">Once you have completed the above-mentioned steps, you need to run the pipeline. On successful execution, you will the results of the pipeline, as shown below:</p><figure id="aec6"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*B64odlqtXEnTWCccAdL3vg.png"><figcaption></figcaption></figure><figure id="11fd"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*Twa9-EfLUoHCwTQNMhZsOA.png"><figcaption></figcaption></figure><p id="56cb">As a result of the last step, the test results will also be published in the Azure DevOps test plan.</p><figure id="35f1"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*mNitgwCQUKgJz7SgGbAXIQ.png"><figcaption></figcaption></figure><div id="fe1d"><pre>Hey,<span class="hljs-built_in"> if </span>you enjoyed this story,<span class="hljs-built_in"> check </span>out Medium Membership! Just $5/month!</pre></div><div id="f0ce"><pre>Your membership fee directly supports me <span class="hljs-keyword">and</span> other writers you <span class="hljs-keyword">read</span>. You’ll <span class="hljs-keyword">also</span> <span class="hljs-keyword">get</span> <span class="hljs-keyword">full</span> <span class="hljs-keyword">access</span> <span class="hljs-keyword">to</span> every story <span class="hljs-keyword">on</span> Medium.</pre></div></article></body>

A Powerful and Practical Way to Load Test APIs

With Apache JMeter, Taurus, and your favorite DevOps platform

Photo by Erik Mclean on Unsplash

As per Wikipedia,

“Continuous testing is the process of executing automated tests as part of the software delivery pipeline to obtain immediate feedback on the business risks associated with a software release candidate.”

In my previous article, I wrote about how to perform functional testing of your APIs using Postman/Newman and integrate it into a DevOps platform. Another important aspect of automated testing is load testing, which helps us analyze the application behavior under stress.

There are various tools available in the market which can help us perform load tests. Apache JMeter is one of the most widely used open-source tools in this field.

This article expects you to have a basic understanding of REST APIs, Apache JMeter, and continuous testing.

Apache JMeter

Apache JMeter helps us perform load tests on various applications like:

  • SOAP/ REST APIs
  • FTP
  • Database via JDBC
  • LDAP
  • Message-oriented middleware (MOM) via JMS
  • Mail — SMTP(S), POP3(S) and IMAP(S)
  • Native commands or shell scripts
  • TCP
  • Java Objects

It provides us with a nice GUI that can be used to create the test plan. It also provides us a command-line utility that helps us run the load test as a headless process. This feature helps us to integrate JMeter into various automation tools.

In this tutorial, I am using a very simple REST API from dummy.restapiexample.com.

Using JMeter, I am going to run the load test on the Get All Employees API.

Prepare and Execute the Test Plan

Using JMeter GUI, you can easily create a test plan that calls the APIs and prepares a summary report, as shown in the screenshot below.

After execution, you can check out the result in the Summary Report section, as shown below.

To get a detailed report, you can run the test plan using the JMeter command-line utility:

jmeter -n -t APITestPlan.jmx -l result.txt -e -o reports/

Here APITestPlan.jmx is the test plan I created in the previous step. result.txtis the file in which test results will be stored, and reports is the folder in which the HTML reports will be created. If you open the reports/index.html page, you will be shown very intuitive results:

You can add complexity to your tests as per business needs.

Taurus

Taurus is an open-source automation framework for running various open-source load-testing tools and functional-testing tools. For regular automated test runs, you need only stick to using Apache JMeter. But if you plan to do continuous testing, then you need to use a tool like Taurus that runs the load tests and produce results in a common format like JUnit results.

Installing Taurus is easy. You can look at the details on the installation page.

pip install --upgrade pip wheel
pip install bzt

Once the installation is done, you need to create a configuration file taurus-config.yml, as shown below:

https://gist.github.com/deshpandetanmay/436cf345667057ad5aead351a03b76d1

In the above script, you need to give the path of the JMeter test plan. Here you need the report in the JUnit format so that you can use the test results and upload those to the DevOps platform. There are other reporting options also available in the Taurus that you may want to explore.

To check if everything is fine, you can run the Taurus command line, as shown below:

bzt taurus-config.yml

Post-run, you will be able to see the detailed reports on the command line, as shown below:

Integrate with Azure DevOps

Now that you are able to execute the tests on your PC/Laptop, it’s time to integrate these into the continuous testing pipelines.

For this, you need to commit the Taurus config file as well as the Apache JMeter test plan file to a Git repo.

Next, you need to create a pipeline, which consists of the following steps:

Here I am using the Azure DevOps hosted agent. If you are using your own agent, then you don’t need to install the pre-requisites on every pipeline run.

  1. Use Python — In this step, you are telling the agent that we need to use Python 3.x.
  2. Install tools — In this step, you are installing the Python tools that will be useful for installing the other tools.
python -m pip install --upgrade pip setuptools wheel

3. Install BZT — In this step, you are installing the Taurus tool.

pip install bzt

4. Run load tests — In this step, you are running the actual load test and gathering results.

bzt loadtests/taurus-config.yml

On a successful run, step 4 will produce an XML file in JUnit format.

Note that Taurus downloads the Apache JMeter binaries if not installed already.

5. Publish test results — In this step, you are publishing the test results to the Azure DevOps test plan. Here you need to give the file name used for writing down the results in JUnit format.

Run the Pipeline

Once you have completed the above-mentioned steps, you need to run the pipeline. On successful execution, you will the results of the pipeline, as shown below:

As a result of the last step, the test results will also be published in the Azure DevOps test plan.

Hey, if you enjoyed this story, check out Medium Membership! Just $5/month!
Your membership fee directly supports me and other writers you read. You’ll also get full access to every story on Medium.
Technology
Programming
Software Engineering
DevOps
Startup
Recommended from ReadMedium