API testing ensures backend services function correctly and reliably. This guide covers everything you need β from HTTP codes to Postman automation and Rest Assured scripting.
πΉ Common HTTP Status Codes & Meanings
- β 200 OK β Request successful
- π 201 Created β New resource created
- β 400 Bad Request β Invalid request syntax
- π« 401 Unauthorized β Authentication required
- β 404 Not Found β Resource does not exist
- π₯ 500 Internal Server Error β Unexpected server issue
π Live APIs for Testing
- JSONPlaceholder β Fake API for testing
- ReqRes β User management testing
- HTTP Stat.us β Simulate HTTP status codes
π Using Postman for API Testing
- Install Postman & create a new request
- Select method (GET, POST, etc.) & enter API URL
- Add parameters or body if needed
- Click Send & check response
- Write assertions in the Tests tab:
// Example Postman Test
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
Use Postman Collection Runner to automate and run tests in batches.
π€ Using Rest Assured for API Automation (Java)
π Maven Dependency:
io.rest-assured
rest-assured
4.4.0
test
π Basic Test Example:
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
public class ApiTest {
public static void main(String[] args) {
given()
.when()
.get("https://jsonplaceholder.typicode.com/posts/1")
.then()
.statusCode(200)
.body("userId", equalTo(1));
}
}
π Key API Testing Concepts
- β Validate Response Codes & Body
- β Header Validation & Authentication
- β Negative Testing for invalid inputs
- β Data-Driven Testing with CSV/JSON
π Advanced API Testing Techniques
- πΉ Mock APIs using Postman Mock Servers
- πΉ Integrate Postman with CI/CD using Newman
- πΉ Generate Reports using Extent Reports in Rest Assured
π API testing plays a vital role in ensuring application reliability. Whether using Postman for manual testing or Rest Assured for automation, mastering these tools boosts quality and efficiency.
β Frequently Asked Questions (FAQs)
1οΈβ£ What is API Testing?
Itβs the process of verifying APIs for correctness, reliability, and performance β ensuring communication between services works as expected.
2οΈβ£ What tools are used for API Testing?
Popular tools include Postman, Rest Assured, SoapUI, and Newman for CI/CD automation.
3οΈβ£ What are common HTTP request methods?
GET (read), POST (create), PUT (update), DELETE (remove), and PATCH (partial update).
4οΈβ£ Can API Testing be automated?
Yes. Rest Assured, Postman + Newman, and other frameworks enable complete automation integrated into CI/CD pipelines.