Consider a REST API contract test where the consumer expects a JSON response with a userId as an integer and userName as a string. The provider returns the following JSON:
{"userId": "123", "userName": "Alice"}What will the contract test most likely report?
Check the expected data types in the contract.
The contract expects userId as an integer, but the provider returns it as a string. This type mismatch causes the test to fail.
Choose the best description of contract testing in REST APIs.
Think about what contract testing ensures between two systems.
Contract testing ensures that the API provider and consumer agree on the structure and data types of requests and responses.
Given this contract test snippet for a REST API consumer:
expect(response).toHaveProperty('data.id');
expect(typeof response.data.id).toBe('number');
expect(response.data.name).toBeDefined();The provider returns:
{"data": {"id": null, "name": "Bob"}}Why does the contract test fail?
Check the expected type of data.id.
The test expects data.id to be a number, but the provider returns null, causing the failure.
Choose the valid JSON schema snippet that requires id as an integer and name as a string in the response object.
Look for correct JSON schema keywords and types.
Option D uses correct JSON schema keywords: type, properties, and required with proper types integer and string.
You have a REST API contract with 5 fields in the response: 2 are required and 3 are optional. To fully test all combinations of optional fields presence or absence along with required fields, how many distinct contract tests are needed?
Think about combinations of optional fields only.
Each optional field can be present or absent independently, so 2^3 = 8 combinations. Required fields are always present, so total tests = 8.