Skip to main content

Performance testing as part of shift-left approach

 


Left-shift testing is a methodology that emphasizes moving testing activities earlier in the software development lifecycle (SDLC). Traditionally, testing happened mostly at the end, which led to delays and increased costs when issues were found. By shifting testing left, you identify and fix problems sooner, leading to a smoother development process and higher-quality software.

Performance testing is a specific type of testing that focuses on measuring and evaluating the non-functional aspects of a system, such as speed, scalability, and responsiveness. This ensures the system can handle expected loads and deliver a good user experience.

So, how do these two concepts connect?

Shift-left testing is particularly valuable for performance testing because:

  • Early detection: Performing performance tests early in development catches issues before they become deeply integrated, making them easier and cheaper to fix.
  • Smaller codebase: Testing smaller units of code individually allows for more focused performance analysis and pinpointing of bottlenecks.
  • Faster feedback: Integrating performance tests into the development workflow provides continuous feedback, enabling developers to optimize their code for performance from the start.

Here are some ways to implement a shift-left approach to performance testing:

  • Unit testing with performance considerations: Include performance checks within unit tests for functions and APIs.
  • API performance testing: Test the performance of individual APIs during development.
  • Load testing for microservices: Perform small-scale load tests on individual microservices to identify potential bottlenecks.
  • Performance profiling: Use profiling tools to analyze code for performance inefficiencies.

Overall, by integrating performance testing into your left-shift testing strategy, you can build higher quality, more performant software while saving time and money in the long run.


Gatling is a powerful open-source tool specifically designed for performance testing. It excels in both traditional load testing and the left-shift testing approach you mentioned earlier. Here's how Gatling can help you achieve performance excellence:

Load Testing:

  • Scalable Simulations: Create realistic user scenarios with customizable load patterns, mimicking real-world usage. Gatling can handle thousands of concurrent users, simulating high traffic situations and identifying potential bottlenecks.
  • HTTP-based and Beyond: Gatling supports various protocols, including HTTP, WebSockets, and Kafka. This allows you to test diverse applications beyond just web interfaces.
  • Comprehensive Metrics: Gatling gathers rich performance data, including response times, error rates, resource utilization, and more. This data helps pinpoint performance issues and track improvements.

Left-Shift Testing:

  • Unit Testing Integration: Gatling integrates with popular testing frameworks like JUnit and ScalaTest, allowing you to add performance checks directly within your unit tests. This catches performance issues early in the development cycle.
  • Microservice-focused: Gatling's modular design makes it ideal for testing individual microservices in isolation, enabling you to identify performance bottlenecks before integration.
  • API Performance: Gatling is perfect for testing the performance of APIs, ensuring they respond quickly and efficiently under various loads.

Getting Started with Gatling:

  1. Installation: Set up Gatling by following the official documentation: <invalid URL removed>
  2. Scenario Creation: Define user scenarios that mimic real-world behavior using Gatling's intuitive Scala DSL.
  3. Simulation Configuration: Specify the desired load pattern, duration, and other simulation settings.
  4. Run and Analyze: Run your tests and analyze the generated reports to identify performance issues and measure improvements.


Here's a sample Gatling test for a simple API call:

Scenario: Test the performance of a GET request to /users endpoint that returns a list of users.

Code:

Scala
import io.gatling.core.Predef._
import io.gatling.core.scenario.Simulation

class ApiTest extends Simulation {

  val httpProtocol = http
    .baseUrl("http://localhost:8080") // Replace with your actual base URL

  val scn = scenario("Get Users")
    .exec(
      http("Get all users")
        .get("/users")
        .check(status.is(200))
        .check(jsonPath("$.length").is(5)) // Assert there are 5 users
    )

  setUp(
    scn.inject(
      atOnceUsers(10) // Send 10 concurrent users at once
    ).during(10 seconds) // Run the test for 10 seconds
  ).protocols(httpProtocol)
}

Explanation:

  • This code defines a simulation named ApiTest that extends the Simulation class.
  • It sets up the httpProtocol your API's base URL.
  • The scn scenario defines the user behavior:
    • It sends a GET request to /users an endpoint.
    • It checks if the response status code is 200 (success).
    • It asserts that the response body contains 5 users using JSONPath.
  • The setUp block configures the test:
    • It injects 10 concurrent users at once.
    • It runs the test for 10 seconds.
    • It sets the httpProtocol as the protocol for all requests.
References:

Comments

Popular posts from this blog

Safety property that a deadlock can never occur

Identified four necessary conditions for a deadlock to occur 1. Mutual Exclusion. The nodes claim exclusive control of the resources they require. 2. Wait for. Tasks hold resources already allocated to them while waiting for additional resources. 3. No preemption. Resources cannot be forcibly removed from the tasks holding them until the resources are used to completion. 4. Cyclic Wait. A cyclic chain of tasks exists, such that each task holds one or more resources that are being requested by the next task in the chain. References: For information about system deadlocks please refer: E. G. Coffman, M. Elphick, and A. Shoshani. System Deadlocks

OWASP API Security Top 10 vulnerabilities 2023

API Security Do's and Don'ts Don't trust input data for an API and do validate all inputs. Ensure you understand security and keep sensitive data out of code. Don't hardcode keys/tokens Don't reveal useful info in error messages. Don't have hidden/unadvertised features. Don't filter data in UI - control at app level Don't confuse authentication and authorization Always use API gateways to control access and traffic Do require API documentation. Do expect users/hackers to find and use undocumented endpoints Do continuous testing - attack simulation, test configs, fuzzing, injections OWASP API Security Top 10 Vulnerabilities 2023 API-1:2023 - Broken Object Level Authorization: BOLA is still the leading vulnerability that plagues APIs. When data objects do not have sufficient access controls in place, resources can be accessed by unauthorized users. API-2:2023 - Broken Authentication  Broken Authentication contains all vulnerabilities associated with auth...
Program to print items in single linkedlist in Pendulum order  Single linked list pendulum in java There are sequence of numbers in a single linked list and display the result in pendulum format Input : 1 2 3 4 5 6 7 8 Output : 1 8 2 7 3 6 5 4 Solution :  https://github.com/Bonu/datastructures/blob/main/SingleLinkedListPendulum.java Below is the manual approach: Input: 1 2 3 4 5 6 7 Iteration 1: 1 2 3 4 5 6 7 Iteration 2: 1 7 2 3 4 5 6 Iteration 3: 1 7 2 6 3 4 5 Iteration 4: 1 7 2 6 3 5 4