Using API spec as an Executable Contract To Mock and Test Microservices
summary
AsyncAPI specifications become executable contracts: Specmatic pulls a spec from Git, spins up a Google Pub/Sub emulator via testcontainers, publishes the example payload to the placeOrder topic, and awaits messages on processOrder and notification topics. Tests are generated dynamically from the spec, validate schemas and enums, catch mismatched keys (e.g. total vs totalAmount), and run locally or in CI. This enables examples-as-payloads driven tests and backward-compatibility testing without handwritten test code.
AI-written summary · about
chapters (11)
- 0:00API specs as executable contracts
- 2:32Problem with handwritten tests
- 3:37Auto-generate contract tests
- 5:04Specmatic PubSub testing demo
- 11:23Request-reply and fan-out patterns
- 12:51API specs catch breaking changes
- 16:50AsyncAPI for API design first
- 19:58Backward compatibility testing
- 21:42Tests and stubs in CI
- 22:46Shift-left testing benefits
- 23:51Summary
related talks
01h 20mContract Driven Development-Deploying MicroServices Without Integration Testing
50mContract-Driven Development
01h 21mContract Driven Development-Deploy MicroServices Independently W/out Integration Testing
33mKafka and JMS Mocking with AsyncAPI using Specmatic
51mContract-Driven Development-Escape Microservices Integration & Deployment Hell
19mGenerating & Using AsyncAPI Specs from Real-World API Data
22mStrategies for Generating Dynamic, Realistic Mocks for Messaging APIs
44mSeamless Upgrades: Mastering API Compatibility
