Service Virtualization
1. Decide Whether To Mock
- Mock only third-party or unstable dependencies.
- Keep real dependencies for the system under test whenever practical.
- Read when-to-mock-vs-real.md before adding stubs.
2. Create The Stub Layer
- Use WireMock for HTTP downstream dependencies.
- Model stable happy-path stubs first.
- Add negative behavior only when the scenario requires it.
- Read wiremock-patterns.md for stub structure.
3. Inject Failure Modes
- Add latency, resets, malformed payloads, and error statuses deliberately.
- Read fault-injection.md before writing resilience tests.
4. Verify Intent
- Assert that the system under test handled the dependency behavior correctly.
- Assert that the stub was called only when interaction verification matters.
5. Examples
- Input:
Simulate the shipping provider timing out.Output: Add a WireMock delayed response and assert the API returns the documented fallback error. - Input:
Stub the tax provider for local CI.Output: Add deterministic success and validation-failure stubs, then route the tests to the stub base URL.
6. Troubleshooting
- Problem: The suite still calls the live dependency. Fix: Verify the service under test points to the stubbed base URL.
- Problem: Contract drift breaks the stub. Fix: Rebuild the stub from the latest contract or response samples.