#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

API Test Cases

What to Cover

  • Positive cases: valid input returns the expected status code and correct data.
  • Negative cases: invalid input (missing fields, wrong data types) returns appropriate error codes and messages.
  • Boundary cases: testing limits, such as maximum field length or pagination edges.
  • Authentication/authorization: requests without valid credentials are correctly rejected.
  • Response structure: confirming the response schema, data types, and required fields are correct.

Example Test Case

For a GET /users/{id} endpoint: input — a valid existing user ID; expected result — status code 200 and a response body containing the correct user's name and email.

A Template That Keeps API Test Cases Consistent

Writing every API test case with the same fields makes reviews faster and makes automation easier later. A practical template has these columns:

FieldWhat to write
ID and titleA short unique ID plus a one-line purpose, e.g. "POST /users rejects missing email"
PreconditionsAuth token, existing records, environment
RequestMethod, endpoint, headers, query params and body
Expected statusThe exact code, such as 201, 400 or 401
Expected bodyKey fields, error message and schema rules
Post-checksDatabase row created, event published, nothing changed on failure

Worked Example: Test Cases for Creating a User

Take POST /users, which accepts name, email and age. One endpoint quickly produces a full set of cases:

IDScenarioExpected
TC01All fields valid201, body returns a new id and the same name and email
TC02Email missing400 with a message naming the email field
TC03Email already registered409 or the documented conflict code; no duplicate row
TC04Age sent as text "twenty"400 with a type error
TC05Name at maximum allowed length201; one character more returns 400
TC06No Authorization header401, and no user is created
TC07Valid token without create permission403
TC08Wrong Content-Type (text/plain)415 or 400, as the API contract says

Notice that failure cases also check the side effect: a rejected request must not leave a half-created record behind.

Turning a Case Into an Automated Check

Once written, the same case can be automated with Rest Assured in Java. This version covers TC02:

@Test
public void createUserWithoutEmailReturns400() {
    given()
        .baseUri("https://api.example.com")
        .header("Authorization", "Bearer " + token)
        .contentType(ContentType.JSON)
        .body("{ \"name\": \"Asha\", \"age\": 24 }")
    .when()
        .post("/users")
    .then()
        .statusCode(400)
        .body("error", containsString("email"));
}

Keep the test name equal to the case title so a failed run points straight back to the written case.

Common Gaps in API Test Suites

  • Checking only the status code and ignoring the response body or headers.
  • Skipping idempotency checks: calling PUT or DELETE twice should behave as documented.
  • Never testing empty lists, pagination beyond the last page or very large page sizes.
  • Hardcoding IDs that only exist in one environment, so tests break elsewhere.
  • Leaving out response time expectations for endpoints users wait on.
  • Not verifying that error messages avoid leaking stack traces or internal details.

Before calling an endpoint covered, confirm you have at least one positive case, one per required field missing, one per data type rule, one for auth failure, one for permission failure and one boundary pair for each length or range limit.

Ready to master real-world software testing?

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

Explore Course