DEV Community

Cover image for πŸš€ Applying API Testing Frameworks: Real-World Examples with Code

πŸš€ Applying API Testing Frameworks: Real-World Examples with Code

API testing is a cornerstone of modern software quality assurance. Whether you're testing RESTful services or SOAP endpoints, having the right framework in your toolbox can make all the difference. In this post, we'll explore how to apply popular API testing frameworks, show real-world examples, and point you to great learning resources, including videos and documentation.

πŸ’‘ If you're still evaluating API testing tools, check out this comparison article:Top 10 API Testing Tools

πŸ“Œ Why API Testing Matters

  • βœ… Detects defects early
  • βœ… Ensures contract compliance
  • βœ… Supports automation pipelines
  • βœ… Works independently of the UI

Frameworks like Postman, REST Assured, Karate, Supertest, and Newman offer varied features like scripting, CI/CD integration, and mocking support.

πŸ”§ 1. REST Assured (Java)
Best for: Java-based automation frameworks
Supports: RESTful APIs

✨ Setup (Maven)

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>5.3.0</version>
    <scope>test</scope>
</dependency>
Enter fullscreen mode Exit fullscreen mode

βœ… Sample Test

import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

class APITest {

    @Test
    void checkUserAPI() {
        RestAssured.baseURI = "https://jsonplaceholder.typicode.com";

        given()
            .when()
            .get("/users/1")
            .then()
            .statusCode(200)
            .body("username", equalTo("Bret"));
    }
}
Enter fullscreen mode Exit fullscreen mode

πŸ“˜ Docs: rest-assured.io
πŸŽ₯ Video: REST Assured Full Course (YouTube)

πŸ₯‹ 2. Karate DSL (Java / DSL)
Best for: BDD-style testing
Supports: REST, SOAP, GraphQL, gRPC
_
✨ Setup (Maven)_

<dependency>
  <groupId>com.intuit.karate</groupId>
  <artifactId>karate-junit5</artifactId>
  <version>1.4.1</version>
  <scope>test</scope>
</dependency>
Enter fullscreen mode Exit fullscreen mode

βœ… Feature File Example

Feature: Get a single user

Scenario: Validate user details
  Given url 'https://jsonplaceholder.typicode.com/users/1'
  When method GET
  Then status 200
  And match response.username == 'Bret'
Enter fullscreen mode Exit fullscreen mode

πŸ“˜ Docs: karatelabs.io
πŸŽ₯ Video: Karate DSL Tutorial (YouTube)

πŸ§ͺ 3. Supertest (JavaScript)
Best for: Node.js apps
Works with: Express.js, Mocha, Jest

✨ Install

npm install --save-dev supertest jest
Enter fullscreen mode Exit fullscreen mode

βœ… Sample Test (with Jest)

const request = require('supertest');
const app = require('../app'); // Your Express app

describe('GET /users/1', () => {
  it('should return a user', async () => {
    const res = await request(app).get('/users/1');
    expect(res.statusCode).toBe(200);
    expect(res.body.username).toBe('Bret');
  });
});
Enter fullscreen mode Exit fullscreen mode

πŸ“˜ Docs: Supertest GitHub

πŸ“« 4. Postman + Newman (JavaScript)
Best for: Manual + Automated tests
Newman: CLI runner for Postman collections

βœ… Use Case: CI/CD Integration

  1. Create your collection in Postman.
  2. Export as collection.json.
  3. Run in CI pipeline:
newman run collection.json
Enter fullscreen mode Exit fullscreen mode

πŸ“˜ Docs: Newman CLI
πŸŽ₯ Video: Postman + Newman CI Tutorial

πŸ› οΈ Bonus: Best Practices

  • πŸ” Use data-driven tests (CSV, JSON)
  • πŸ” Secure sensitive data (use .env files or vaults)
  • πŸ§ͺ Automate in CI/CD using GitHub Actions, GitLab CI, Jenkins
  • πŸ“„ Generate reports (Allure, Newman HTML Reporter)

πŸ™Œ Final Thoughts
API testing is no longer optionalβ€”it's essential. Start small, automate progressively, and pick a framework that aligns with your team’s tech stack and workflow. Whether you're coding in Java or JavaScript, there's a tool to fit your needs.

If you liked this article, don’t forget to:

πŸ‘‰ Bookmark it
πŸ—£οΈ Share it with your QA/dev team
πŸ’¬ Comment your favorite API testing tool

Top comments (0)