Middle
Milliseid teeke kasutasite API testide automatiseerimiseks? Kuidas te vastuseid valideerisite?
sobes.tech AI
Vastus AI-lt
To automate API testing, I often use libraries such as RestAssured (Java), Requests + Pytest (Python), SuperTest (JavaScript/Node.js), and Postman/Newman for integration tests.
Response validation usually includes:
- Checking the HTTP status (e.g., 200 OK)
- Validating the structure and content of JSON/XML using JSON Schema or XPath
- Checking the values of specific fields
Example with RestAssured:
given()
.when().get("/api/users/1")
.then()
.statusCode(200)
.body("data.id", equalTo(1))
.body("data.email", matchesPattern(".+@.+\\..+"));
Here, we verify the status, the presence of the correct id, and the email format.