Middle
Give an example of how you would select test cases for a PUT request?
sobes.tech AI
Answer from AI
To select test cases for a PUT request, I would apply the following approaches, focusing on different aspects:
-
Valid data:
- Creating/updating a record with correct, complete data.
- Changing only some fields, leaving others unchanged.
- Updating all fields to new, valid values.
- Using boundary values for numeric fields (minimum, maximum).
- Using various data formats allowed by the specification (e.g., date, time).
-
Invalid data:
- Passing data with incorrect field types (e.g., string instead of number).
- Passing data that violates string length or number range constraints.
- Passing data that violates field uniqueness (if applicable).
- Passing data with incorrect formats (invalid date, email).
- Omitting required fields.
- Passing empty strings or null for fields that should not be empty.
-
Resource existence:
- PUT request to an existing resource.
- PUT request to a non-existent resource (expecting 404 response).
-
Authorization and authentication:
- PUT request with correct user credentials authorized to modify the resource.
- PUT request with incorrect or missing credentials (expecting 401 Unauthorized or 403 Forbidden).
- PUT request from a user without necessary rights to modify the resource (expecting 403 Forbidden).
-
Synchronization and concurrency:
- Simultaneous PUT requests to the same resource (e.g., using etag).
-
Error handling:
- PUT request that should trigger a server-side error (e.g., due to internal failure).
Example table of test cases:
| ID | Test case description | Preconditions | Test data (part of request) | Expected result | HTTP Code |
|---|---|---|---|---|---|
| PUT-001 | Updating an existing resource with valid data | Resource with ID=123 exists | { "name": "New Name", "value": 100 } |
Resource successfully updated, data matches request | 200 |
| PUT-002 | Updating an existing resource with partial update | Resource with ID=123 exists | { "name": "Only Name Changed" } |
Resource successfully updated, only name changed | 200 |
| PUT-003 | Attempting to update a non-existent resource | Resource with ID=999 does not exist | { "name": "Non Existent Update" } |
Resource not found | 404 |
| PUT-004 | Updating resource with invalid data type | Resource with ID=123 exists | { "value": "not_a_number" } |
Data validation error | 400 |
| PUT-005 | Updating resource without authentication | Resource with ID=123 exists, request without token | { "name": "Unauthorized Change" } |
Unauthorized | 401 |
Each test case should be atomic and verify a specific aspect of the PUT request functionality.