Middle
Provide an example of how you would select test cases for a PUT request?
sobes.tech AI
Answer from AI
I would select test cases based on the following:
-
Successful update:
- Updating all fields with valid values.
- Updating one or more fields, leaving others unchanged.
- Updating fields with boundary values (if applicable).
-
Unsuccessful update (negative tests):
- Invalid data:
- Incorrect data format for fields (e.g., string instead of number).
- Values exceeding maximum length or outside the allowed range.
- Missing required fields in the request body.
- Non-existent resource:
- PUT request with an ID that does not exist in the system.
- Data conflict:
- Attempting to update a resource that has been modified by another user (if versioning or locking mechanisms are used).
- Permission issues:
- Attempting to update a resource without proper access rights.
- Validation errors:
- Violations of business logic or database constraints (e.g., duplicate unique value).
- Incorrect Content-Type:
- Sending a request with a Content-Type different from expected (e.g.,
text/plaininstead ofapplication/json).
- Sending a request with a Content-Type different from expected (e.g.,
- Empty request body:
- Sending a request without a body.
- Invalid data:
-
Boundary conditions:
- Updating a resource with the minimal set of fields (if allowed).
- Updating a resource with the maximum set of fields.
- Testing behavior when additional, unexpected fields are included in the request body.
Example structure of test cases:
| Case | Description | Expected result |
|---|---|---|
| Successful update | Updating all fields with correct values. | 200 OK / 204 No Content (depends on API) |
| Non-existent ID | Attempting to update a resource with an ID that does not exist. | 404 Not Found |
| Invalid data format | Attempting to update a numeric field with a string. | 400 Bad Request |
| Missing required field | Missing a required field in the request body. | 400 Bad Request |
| Insufficient permissions | Attempting to update a resource without necessary rights. | 403 Forbidden |
For automation, I would use frameworks like RestAssured (Java), Requests (Python), or Supertest (Node.js), along with tools for generating test data.