Senior
How to properly test changing an API contract (adding a new mandatory field)?
sobes.tech AI
Answer from AI
When testing an API contract change with the addition of a new mandatory field, it is important to check several aspects:
- Backward Compatibility Check: Ensure that clients not passing the new field receive correct errors or warnings.
- Validation of the new field: Verify that the API correctly handles the absence, incorrect, and correct values of the new mandatory field.
- Integration Testing: Check that all services interacting with the API handle the change correctly.
- Documentation: Make sure the documentation is updated and reflects the new mandatory field.
Example of testing the addition of a mandatory field in JSON:
// Request without the new mandatory field
{
"existingField": "value"
}
// Expected response: error indicating the missing field
// Request with the new mandatory field
{
"existingField": "value",
"newMandatoryField": "validValue"
}
// Expected response: successful processing
Automating such tests will help quickly identify regressions as the API evolves.