Performance testing is an integral step in the lifecycle of company applications and products. Amplifying speed, scalability, automated performance tests allows stakeholders to identify all kinds of obstacles in their applications and ensure a smooth user experience. Performance testing is in high-demand across the industry, and it’s a valuable, competitive skill you can add to your resume or profile.
If you’re looking to expand your understanding of performance testing, this article is for you. Today, we will go over the basics of performance testing and teach you the in-demand tools for automated testing: Gatling and Jenkins.
Today, we will cover the following:
Gain the necessary fundamentals of Gatling, Jenkins, and Lighthouse to run automated tests smoothly, including scalability testing and stress testing.
Performance Test Automation 101: Gatling, Lighthouse, & Jenkins
Performance testing is a comprehensive process of checking for the speed, stability, response time, reliability, and resource usage of a program or product under various workloads. Performance testing allows you to identify and eliminate potential performance bottlenecks in your software.
Typically, performance testing is done through a series of quantitative tests done in a lab or a production environment. To identify bottlenecks, the typical parameters used are processing speed, data transfer rate, network bandwidth, workload efficiency, and reliability.
There are five main types of performance testing that can be used to improve different facets of an application’s performance.
Performance testing allows stakeholders to identify bottlenecks within software. A bottleneck is a single point that holds back the overall performance of an application. By identifying bottlenecks, you can highlight areas where the application might fail or lag.
With performance testing, you can identify where the software needs to improve before going public. And without it, applications could face a series of issues, such as slow runtime or inconsistencies across operating systems.
Without performance testing, we encounter all sorts of issues in our code and products, including poor response time, long load time, poor scalability, and bottlenecks.
Organizations use KPIs (key performance indicators) to evaluate the performance of their software during performance testing. Here are some common metrics:
Now that, we understand the basics of performance testing, let’s learn about the most widely used open-source performance testing tools. In this article, we will learn about Gatling and Jenkins, but it’s important to know what else is out there.
Gatling
Gatling is a load testing tool that uses Akka actors to simulate a large load of users. These tests are written in Scala and use DSL. Gatling is designed for ease of use, high performance, and maintainability. Gatling is a widely popular tool for load testing, with more than 5 million downloads and thousands of companies using it for testing. Gatling offers free versions and a paid enterprise version.
Locust
Locust is an open-source load testing tool written in Python. Locust is distributed and scalable, so it can support a large load of simultaneous users over multiple machines. With Locust, you can define user behavior in code, so there is no need for clunky UIs or XML. In a locust test, a “swarm” of locusts attacks your target site. Each locust’s behavior is configurable, and you can monitor the swarm in real-time.
Jmeter
Jmeter is an open-source load and performance testing tool written in Java. It supports a variety of applications, servers, and protocols including HTTP, TCP, SOAP, Web, LDAP, etc. It is one of the most popular performance testing tools available.
Lighthouse
Lighthouse is used for measuring website performance. It is an open-source, automated tool used to improve the quality of web pages. It offers audits for performance, accessibility, PWAs, SEO, and more. Once you give Lighthouse a URL, it will run audits against the page and generate a report. The metrics can can be used to improve the site.
In the world of software, there are two kinds of testing: manual and automated. The process that we introduced to you above is for the most part, manual. Test automation involved running tests automatics, managing the test data, and utilizing the results to improve your software quality.
This is typically achieved by writing scripts and using automation testing tools like Gatling, a highly capable load testing tool. The architecture of Gatling is asynchronous as long as the underlying protocol, such as HTTP/HTTPS, is implemented in a non-blocking way.
This architecture allows us to utilize virtual users instead of using dedicated threading. Therefore, running thousands of concurrent virtual users is no problem compared to a thread-based load testing tool like JMeter.
Stress testing, also known as endurance testing, verifies the system’s error handling capability and its reliability under extreme, prolonged conditions.
Sample:
In the example below, we send requests to https://api.coingecko.com to fetch the cryptocurrency derivatives.
import io.gatling.core.Predef._import io.gatling.http.Predef._import scala.concurrent.duration._class SampleSimulation extends Simulation {val httpProtocol = http.baseUrl("https://reqres.in/api/users").acceptHeader("*/*").doNotTrackHeader("1").userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0").disableWarmUp.disableCachingval getScenario = scenario("BasicSimulation - GET").exec(http("GET request").get("/").check(status.is(200)))setUp(getScenario.inject(rampUsers(2) during (2 seconds))).protocols(httpProtocol)}
Create the global HTTP configuration
In the code snippet below, we can create a global HTTP configuration:
val protocols = http.disableCaching.disableWarmUp.baseUrl("https://api.coingecko.com").contentTypeHeader("application/json").acceptHeader("application/json")
Learn performance testing without scrubbing through videos or documentation. Educative’s text-based courses are easy to skim and feature live coding environments - making learning quick and efficient.
Performance Test Automation 101: Gatling, Lighthouse, & Jenkins
Create the user scenario
In the code snippet below:
Creates a user scenario containing an HTTP exec
for making a GET request to /api/v2/derivatives/exchanges
, in which the base URL is picked up from global HTTP configuration.
Asserts the status code and checkers whether the id
fields exist in the response.
val scn = scenario("fetching all derivatives").exec(http("fetch all derivatives").get("/api/v3/derivatives/exchanges").check(status.is(200),jsonPath("$[*].id").exists))
Set up user injection profile
We create the user injection. In our case, we execute the user scenario at a constant rate of 2 times for 10 seconds. Once the simulation is done, we assert whether the number of failed requests is 0.
setUp(scn.inject(constantUsersPerSec(5) during (10 seconds))).protocols(protocols).assertions(global.failedRequests.count.is(0))
Continuous Integration (CI) is the first phase of the automated release pipeline. It’s a way to get early feedback on developers’ code changes using an automated test suit. The process:
The CI process is set up by using acceptance tests for code changes. Automated performance tests in the CI process can be done using only roughly 5% of the actual load.
This allows us to receive early feedback and evaluate the impact of the newly committed code. If there are any bottlenecks or issues, we can immediately analyze and fix the problem on the spot before going live.
The below guide will provide the steps for you to install Jenkins locally or on a remote machine.
/bin/bash -c "$(curl -fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install jenkins
brew services start jenkins
The screen below will ask you for password to complete your installation along with the password location. Follow the instructions below.
Now Jenkins is set up and ready to be used with Gatling!
Follow the below steps to install the plugin.
Manage Jenkins
option on the left side panel.Manage Plugins
option, as shown below.Select the available
tab, search for Gatling plugin, select the Gatling plugins
, and select the Download now
option. Install it after restarting.
Once the plugin is installed, you can restart from the UI option as shown below or via the command line using brew, as discussed in the previous lesson.
Once the Jenkins is restarted, you can see the Gatling under installed plugins (manage plugins -> installed plugins).
Now we are all set to use the Gatling plugin for creating our load testing job, which can also be used in the CI flow!
Congratulations! Now, you should have a good idea of performance testing. These skills are super valuable for any company, so adding them to your resume is a sure way to stand out as a candidate.
There’s still a lot to learn! The next steps to master Gatling and performance testing are:
To get started with these concepts and processes, check out Educative’s course Performance Test Automation 101. In this course, you’ll learn the fundamentals of Gatling for scalability testing and stress testing. You’ll then learn how to write Gatling scripts, understand web page performance, and simulate network throttling.
By the end of this course, you will have some new great skills for your resume.
Happy learning!
Free Resources