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

React JS Basics

  What are side effects in React? In React, side effects are operations that interact with external systems or cause changes outside the component's rendering process. These can include: Data fetching: Retrieving data from APIs or other sources. Subscriptions: Setting up listeners for events or data changes. Timers: Creating timers for delayed actions or animations. DOM manipulation: Directly modifying the DOM (rarely used in modern React with declarative approach). Why use useEffect ? In class-based components, you would typically use lifecycle methods like componentDidMount , componentDidUpdate , and componentWillUnmount to handle side effects. Functional components don't have these methods directly. The useEffect Hook provides a way to manage side effects in functional components. It allows you to run a function after a component renders (or re-renders) and optionally clean up any resources created by that function before the component unmounts. How does useEffect wor...

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...

Next.js vs react

Next.js builds upon React and offers several advantages over using React alone: Key Advantages of Next.js over React: Server-Side Rendering (SSR) and Static Site Generation (SSG): Next.js provides built-in support for SSR and SSG, leading to faster initial page loads, improved SEO, and better performance for content-heavy applications. Simplified Routing: Next.js offers a file-based routing system, making it easier to manage routing configurations compared to React, where you might need to use additional libraries like React Router. Automatic Code Splitting: Next.js automatically splits your JavaScript code into smaller chunks, optimizing page load times by loading only the necessary code for each page. API Routes: Next.js allows you to easily create serverless API endpoints within your Next.js project, simplifying backend integration. Image Optimization: Next.js includes an optimized image component that automat...