DEV Community

Cover image for ๐Ÿš€ Applying API Testing Frameworks: Real-World Examples with Code
Walter Emmanuel Salas Jimenez
Walter Emmanuel Salas Jimenez

Posted on

๐Ÿš€ 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)