External System Contract Tests
External System Contract Tests verify that our System can communicate with External Systems, also providing us assurance that the External System Stubs used in the Acceptance Tests are valid.
🔒Hello, this is Valentina with a premium issue of the Optivem Journal. I help Engineering Leaders & Senior Software Developers apply TDD in Legacy Code. This article is part of the TDD in Legacy Code series. To get these articles in your inbox every week, subscribe:
What are External System Contract Tests?
External System Contract Tests verify that our System can communicate with External Systems; that we have a valid expectation regarding their contracts.
If the External System Contract Test passes when executed for both the External System Test Instance and External System Stub, the Stub has a matching contract
If the External System Contract Test passes when executed against the External System Test instance, but fails when executed against the External System Stub, w need to make corrections to our External System Stub
If the External System Contract Test fails when executed against the External System Test Instance, we’ve got wrong expectations or the External System has changed - we need to update the External System Contract Test and the External System Stub
External System Contract Tests target (and span) the External System Test Instances.
If we have the possibility to deploy the External System Test Instances (e.g. self-hosted ERPNext), then we deploy them to the E2E Environment and run External System Contract Tests on those instances
However, if the External System Test Instances already exist outside of our environment (e.g. PayPal Developer Portal), then we run the External System Contract Tests against those instances
For each External System, we would have some External System Contract Tests. As part of test execution, we should be able to “switch“ the connection between some External System Test Instance and the External System Stub. In that way, the External System Contract Test is written once, but can be executed against both.
Why External System Contract Tests?
Within Acceptance Tests, we’d seen how E2E Tests are limited because they can only test some Acceptance Criteria, whereas Acceptance Tests are able to test all the Acceptance Criteria.
So, can we just replace the E2E Tests with Acceptance Tests?
This would be problematic for the following reason: ⬇️⬇️⬇️