Imagine two teams working on different parts of a software system. One team builds a service (provider), and the other builds a client (consumer) that uses that service. What is the main goal of contract testing between these two teams?
Think about what needs to be agreed upon between two separate parts that communicate.
Contract testing focuses on verifying that the provider and consumer agree on the contract, which defines the data format and interaction rules. This prevents integration issues without testing the entire system.
Given this simplified contract test result output, what does it indicate?
Contract Test Result:
Consumer: OrderApp
Provider: PaymentService
Test: PaymentService accepts order payment request
Result: FAIL
Error: Expected field 'amount' to be a number but got string
Look at the error message carefully about the 'amount' field type.
The test failed because the provider returned a string for the 'amount' field, but the contract expects a number. This mismatch causes the contract test to fail.
You want to write an assertion in your contract test to check that the provider's response field status is a string with value 'success'. Which assertion is correct?
Remember Python syntax for assertions and type checking.
Option A correctly uses '==' for comparison and 'type(...) == str' to check the type. Option A is redundant but valid; however, D is more concise and correct. Option A uses 'or' which is incorrect logic. Option A uses '=' which is assignment, causing syntax error, and compares type to string literal 'string' which is invalid.
Review this contract test snippet and identify why it raises a KeyError:
response = provider.get_order(123) assert response['orderId'] == 123 assert response['total'] > 0 assert response['status'] == 'confirmed'
Check which keys are accessed and whether they exist in the response.
The KeyError occurs because the response dictionary lacks the 'status' key. Accessing a missing key with [] raises KeyError in Python.
You want to implement consumer-driven contract testing where the consumer defines the contract and the provider verifies it automatically during CI. Which framework is best suited for this?
Look for a framework specialized in contract testing between services.
Pact is a popular framework for consumer-driven contract testing. It allows consumers to define contracts and providers to verify them automatically. Selenium is for UI testing, JUnit is a unit testing framework, and Postman is for API testing but not specialized for contract testing.