#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
API Testing

What is API Automation testing

Definition

API automation testing is the practice of writing scripts that send requests to an API and automatically verify the responses — status codes, headers, and body content — without manual intervention.

How It Differs From Manual API Testing

Manual testing (e.g., in Postman) is exploratory and quick to set up but doesn't scale well for regression; automated tests (e.g., in Rest Assured) run repeatedly, reliably, and can be integrated into a build pipeline.

Typical Tools

Common tools include Rest Assured (Java), Postman/Newman, and various framework-specific HTTP client libraries.

What a Good API Test Checks

Checking only for a 200 status code misses most bugs. A useful automated API test looks at several layers of the response.

  • Status code: 201 after creating a record, 400 for bad input, 401 without a token, 404 for a missing item.
  • Body values: fields hold the expected data, for example the name you just sent.
  • Schema: required fields exist and have the right types.
  • Headers: content type, caching and security headers.
  • Response time: stays within an agreed limit.
  • Side effects: a follow-up GET shows the change really happened.

Example: Create and Verify a User

This Rest Assured test sends a POST, checks the reply, then reads the new record back.

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
import io.restassured.http.ContentType;
import org.testng.annotations.Test;

public class UserApiTest {

    private static final String BASE = "https://api.example.com";

    @Test
    public void createUserAndFetchIt() {
        String body = "{\"name\":\"Neha\",\"role\":\"tester\"}";

        int id =
            given()
                .baseUri(BASE)
                .contentType(ContentType.JSON)
                .body(body)
            .when()
                .post("/users")
            .then()
                .statusCode(201)
                .body("name", equalTo("Neha"))
                .time(lessThan(2000L))
                .extract().path("id");

        given().baseUri(BASE)
        .when().get("/users/" + id)
        .then().statusCode(200).body("role", equalTo("tester"));
    }

    @Test
    public void rejectsMissingName() {
        given().baseUri(BASE).contentType(ContentType.JSON).body("{}")
        .when().post("/users")
        .then().statusCode(400);
    }
}

The second test matters as much as the first. Negative tests confirm the API rejects bad data instead of storing it.

Where API Tests Fit in the Test Pyramid

API tests sit between fast unit tests and slower UI tests. They run in seconds, do not break when a button moves, and reach business logic directly. Many teams therefore cover most functional checks at the API level and keep only a small number of end-to-end UI journeys.

  1. Developers write unit tests for individual functions.
  2. Testers and developers automate API tests for each endpoint and key workflow.
  3. A few UI tests confirm that the screens are wired to the API correctly.

Running Tests Automatically

Store tests in the same repository or a linked one and run them on every build with mvn test or Newman. Point them at a test environment through configuration, never hard-coded URLs, and publish the reports so failures are visible to the whole team.

Common Mistakes

  • Tests that depend on each other's data and fail when run in a different order.
  • Hard-coding tokens that expire, instead of logging in at the start of the run.
  • Asserting the entire JSON body as a string, so harmless field order changes break tests.
  • Leaving test records behind; clean up or use unique data for each run.
  • Skipping error cases such as missing fields, wrong types and unauthorised calls.
  • Checking only the happy path for one user role, when permissions differ between roles.

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course