Test Overview
This test checks if a service provider meets the expectations defined by a consumer contract. It verifies that the provider returns the correct response for a given request.
This test checks if a service provider meets the expectations defined by a consumer contract. It verifies that the provider returns the correct response for a given request.
import unittest class ProviderService: def get_user(self, user_id): # Simulate provider response if user_id == 1: return {"id": 1, "name": "Alice"} else: return None class ContractTest(unittest.TestCase): def setUp(self): self.provider = ProviderService() def test_get_user_contract(self): # Consumer expects user with id 1 and name Alice expected_response = {"id": 1, "name": "Alice"} actual_response = self.provider.get_user(1) self.assertEqual(actual_response, expected_response) if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test framework initializes and prepares to run tests | - | PASS |
| 2 | ProviderService instance is created | ProviderService ready to respond to requests | - | PASS |
| 3 | Calls get_user(1) on ProviderService | ProviderService processes request for user id 1 | - | PASS |
| 4 | Receives response {"id": 1, "name": "Alice"} | Response matches expected contract | Check if actual response equals expected response {"id": 1, "name": "Alice"} | PASS |
| 5 | Test completes successfully | All assertions passed, contract is fulfilled | - | PASS |