Junior — Middle
How do you test API correctness and reliability?
sobes.tech AI
Answer from AI
API testing for correctness and reliability involves several stages:
- Functional testing — verifying that the API returns expected responses to correct requests, handles errors and exceptions.
- Boundary and negative testing — sending incorrect, empty, or overly large data to test stability.
- Performance and load testing — checking how the API behaves under high load.
- Security testing — tests for authentication, authorization, vulnerabilities (e.g., SQL injections).
- Test automation using tools (Postman, REST Assured, JMeter) for regular reruns.
Example of a simple test to check API response using REST Assured in Java:
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
public class ApiTest {
public void testGetUser() {
given()
.when().get("https://api.example.com/users/1")
.then()
.statusCode(200)
.body("id", equalTo(1))
.body("name", notNullValue());
}
}