API Test Automation
Learn how to automate API testing using various frameworks and tools. This is a foundational concept in quality assurance and test automation that professional developers rely on daily. The explanations below are written to be beginner-friendly while covering the depth and nuance that comes from real-world Software Testing experience. Take your time with each section and practice the examples
40 min•By Priygop Team•Last updated: Feb 2026
API Automation Frameworks
- RestAssured (Java): Fluent API for REST testing
- Newman (Node.js): Command-line collection runner
- Pytest (Python): Python testing framework
- Karate: API testing framework
- Cypress: End-to-end testing with API support
RestAssured API Testing
Example
// RestAssured Maven Dependency
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.3.2</version>
</dependency>
// Basic RestAssured Test
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
public class APITest {
@Test
public void testGetUser() {
given()
.baseUri("https://api.example.com")
.header("Authorization", "Bearer token123")
.when()
.get("/users/123")
.then()
.statusCode(200)
.body("id", equalTo(123))
.body("name", notNullValue())
.body("email", containsString("@"))
.time(lessThan(2000L));
}
@Test
public void testCreateUser() {
String userJson = """
{
"name": "John Doe",
"email": "john@example.com",
"password": "securepass123"
}
""";
given()
.baseUri("https://api.example.com")
.contentType("application/json")
.body(userJson)
.when()
.post("/users")
.then()
.statusCode(201)
.body("id", notNullValue())
.body("name", equalTo("John Doe"))
.body("email", equalTo("john@example.com"))
.body("status", equalTo("active"));
}
@Test
public void testUpdateUser() {
String updateJson = """
{
"name": "John Updated",
"email": "john.updated@example.com"
}
""";
given()
.baseUri("https://api.example.com")
.contentType("application/json")
.body(updateJson)
.when()
.put("/users/123")
.then()
.statusCode(200)
.body("name", equalTo("John Updated"))
.body("email", equalTo("john.updated@example.com"));
}
@Test
public void testDeleteUser() {
given()
.baseUri("https://api.example.com")
.when()
.delete("/users/123")
.then()
.statusCode(200)
.body("message", equalTo("User deleted successfully"));
}
}
// Data-Driven API Testing
@DataProvider(name = "userData")
public Object[][] getUserData() {
return new Object[][] {
{"John Doe", "john@example.com", "pass123"},
{"Jane Smith", "jane@example.com", "pass456"},
{"Bob Johnson", "bob@example.com", "pass789"}
};
}
@Test(dataProvider = "userData")
public void testCreateUserWithData(String name, String email, String password) {
String userJson = String.format("""
{
"name": "%s",
"email": "%s",
"password": "%s"
}
""", name, email, password);
given()
.baseUri("https://api.example.com")
.contentType("application/json")
.body(userJson)
.when()
.post("/users")
.then()
.statusCode(201)
.body("name", equalTo(name))
.body("email", equalTo(email));
}Try It Yourself — API Testing & Web Services
Try It Yourself — API Testing & Web ServicesHTML
HTML Editor
✓ ValidTab = 2 spaces
HTML|32 lines|1605 chars|✓ Valid syntax
UTF-8