Lifecycle for Interactions
The overall lifecycle of a contract test is:
-
Define a contract
- Define the interactions
- Run tests to confirm the interactions are correct
- Upload contracts to a broker
-
Verify the contract:
- Download contract from the broker
- Verify the contract
- Publish verification result to the broker
Zooming in on the run tests step
In order to define interactions, it's useful to understand how the interactions will be run. The general lifecycle for all ContractCase interactions is:
- Define interaction
- Set up mock
- Call state setup handlers (if any)
- Invoke
trigger
to call mock- Compare mock expectations
- Return appropriate response
- Invoke
testResponse
ortestErrorResponse
function - If everything was successful, record successful interaction in contract.
If any of the steps or comparisons failed, the whole contract is failed.
- Call state teardown handlers (if any)
- (Later, at the provider side, during verification) re-run steps 2-5.
ContractCase handles most of the lifecycle for you. Not all ContractCase interaction types need to have all lifecycle steps defined by the user - for example, ContractCase defines and invokes its own triggers when testing HTTP servers. For information on which lifecycle you should define for each ContractCase interaction type, see the relevant contract definition or contract verification guides.