VST

Uncategorized

Gatling: Unleashing Peak Performance in Testing

Performance testing plays a pivotal role in software development, ensuring the capability of applications to manage real-world traffic and loads.

Let us use a hypothetical example of ‘Online Shopping Website’ to explain the concept of performance testing.

Imagine you are the owner of an online shopping website, and you want to ensure that your website can handle a large number of users without slowing down or crashing, especially during peak shopping seasons. Performance testing in this context becomes crucial to verify the website’s capability to sustain high user loads and deliver optimal performance under varying conditions.

Performance testing for an online shopping website can be done by testing, if platform can handle normal and peak loads without slowing down, identifying its maximum capacity, assessing scalability as user numbers grow, evaluating how well it copes with sudden traffic spikes. These tests collectively aim to guarantee a smooth and responsive user experience under various conditions.

Performance testing using Gatling:

Gatling, a Scala-based open-source load testing tool, seamlessly integrates with Java, allowing the creation of robust performance tests for web applications and APIs.

In this article, we will look at how to use performance testing with the Karate framework, Gatling, and Java. We will also discuss its pros, cons, and key features.

Let us begin by discussing first Karate Framework,

  • Karate framework is a open source test automation framework and employs its own Domain Specific Language (DSL)
  • Karate utilizes the Gherkin language in feature files for test composition.
  • Additionally, Karate tests work smoothly together with Gatling, which is a free tool for testing system loads and is created using the Scala programming language.

Usage:

Performance testing using Karate, Gatling, Scala, and Java

1] Karate Framework

  • Karate framework is used to develop the test scripts using BDD, Gherkin language.

2] Gatling and Scala:

  • Gatling tool along with Scala is used to build a performance test, simulation, and load generation.

3] Java:

  • Java code is utilized for generating specific dynamic test data and customized functionality as per application specification and requirement.

Structure:

The structure of karate framework integrated with Gatling, Java, Karate and Maven is as follow;

Framework Structure

The Scala injection Gatling script:

setUp(
  createPatient.inject(
    nothingFor(4), // 1
    atOnceUsers(10), // 2
    rampUsers(10).during(5), // 3
    constantUsersPerSec(20).during(15), // 4
    constantUsersPerSec(20).during(15).randomized, // 5
    rampUsersPerSec(10).to(20).during(10.minutes), // 6
    rampUsersPerSec(10).to(20).during(10.minutes).randomized, // 7
    stressPeakUsers(1000).during(20) // 8
  ).protocols(httpProtocol)
)

gatling-akka.conf:

gatling-akka.conf file is used for the throughput and thread pool executor to increase/decrease thread pool.

akka {
  actor {
    default-dispatcher {
      type = Dispatcher
      executor = "thread-pool-executor"
      thread-pool-executor {
        fixed-pool-size = 100
      }
      throughput = 1
    }
  }
}

Key Features:

  1. Easy Execution: Test suites can be executed using maven commands like clean test/ clean test-compile gatling:test -Dgatling.simulationClass=performance.PerformanceTest.
  2. Reports and Analytics: Gatling provides detailed HTML reports and performance analytics, allowing you to analyze test results effectively and identify performance bottlenecks.
  3. Built-In Assertions: Built-in assertions are available to validate multiple attributes like response status code, response, response time, headers, etc.
  4. Performance Testing: Ability to test the performance of an application using Gatling.
  5. Integration: Easily integrate with unit testing frameworks like JUnit, TestNG
  6. Custom Code: Karate Allows custom user-defined functions written in Java/JS.
  7. Markers: Assertion capabilities using Markers like #ignore, #null, #notnull, #boolean
  8. Scenario Simulation: With Gatling’s scenario simulation, you can define virtual user behavior and interactions with your web application or APIs, simulating real-world scenarios.
  9. Load Injection Profiles: Gatling offers different load injection profiles (ramp-up, constant, etc.) to simulate various traffic patterns and test how your application handles different user loads.
  10. Reusability:
  • Re-usable scripts and feature files that may be called from other scripts and feature files.
  • CSV Feeder functionality is available for the use of the external test data with different options like circular, etc.
  • Token feeder is used by using java code and collections.
  • Embedded JavaScript engine that allows writing reusable functions in JavaScript.
  • Re-use of payload data and user-defined functions across tests.

Test Reporting:

Karate Framework supports reporting as:

  1. Cucumber Report
  2. HTML Report
  3. Gatling Report

Gatling Reporting:

Report_1
Report_2
Report_3
Report_4
Report_5
Report_6
Report_7

Add Ons:

  1. No programming expertise is needed.
  2. It supports popular Cucumber standards.
  3. Test Scripts are easy to understand.
  4. It Supports Native JSON & and XML.
  5. Good Documentation is available.
  6. Easy integration into CI/CD tools like Jenkins, Bamboo, Team City, and GitHub actions.
  7. Built-in Native Rest Reports. Plus, it can be integrated with the Cucumber for better UI Reports and more clarity.
  8. Reusability – Multiple feature files can be called a single feature file.
  9. Generates detailed logs and reports.

Ref Links:

https://www.karatelabs.io/

https://gatling.io/docs/gatling/reference/current/core/simulation/

Tags:
Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Test Automation Streamlining REST API Processes with Postman Automation Summary:In today's world, industries are increasingly focusing on the development of...

Uncategorized Enhancing Test Efficiency with Playwright, TestNG and Allure Summary:Playwright is an open-source library developed by Microsoft for automated browser...

Test Automation Continuous Integration and Delivery with Jenkins and GitHub Summary: Testing and deployment-related operations can be automated with Jenkins,...

Mobile App Test Automation with TDD Telecommunications (Cable) Location Performance Testing CONTEXT Elyments is an India-based mobile application similar to...

Leave a Reply

Your email address will not be published. Required fields are marked *