Contract testing features are available through the
simulator test subcommand. See the simulator documentation for details.Quick reference
Run contract tests against a real API:- Complete parameter reference
- Usage examples
- Output format details
- Compatibility policies
What is contract testing?
Contract testing ensures that:- API contracts are honored: Real APIs match their specifications
- Breaking changes are detected: Incompatibilities are caught early
- Multiple environments work: Staging and production stay in sync
- Documentation is accurate: Service definitions reflect reality
Core concepts
Contract
A service definition file that specifies:- Expected endpoints
- Request/response schemas
- Status codes
- Headers
Real API
The actual implementation you’re testing against:- Development server
- Staging environment
- Production API
Compatibility policy
Rules for what constitutes a breaking change:- Strict: Exact match required
- Tolerant: Allow additional fields
- Custom: Define your own rules
Test workflow
- Define contract: Create service definition
- Run tests: Execute against real API
- Review results: Check compliance score
- Fix issues: Update API or contract
- Automate: Add to CI/CD pipeline
Common use cases
Development
Verify your API implementation matches the design:Staging validation
Ensure staging environment is production-ready:Production monitoring
Continuously verify production API compliance:CI/CD integration
Add to your test pipeline:Results interpretation
Compliance score
Percentage of scenarios that passed:- 100%: Perfect compatibility
- 90-99%: Minor issues
- Below 90%: Significant problems
Issue severity
- Critical: Breaking changes
- Major: Compatibility problems
- Minor: Documentation mismatches
- Info: Suggestions
Compatibility status
- Compatible: All critical scenarios pass
- Incompatible: Breaking changes detected
Best practices
Version contracts
Keep contracts in version control alongside code
Test early
Run tests during development, not just before release
Automate
Integrate into CI/CD for continuous validation
Monitor production
Regularly test production APIs for drift
Comparison with other testing
| Type | Contract Testing | Unit Testing | Integration Testing |
|---|---|---|---|
| Scope | API interface | Individual functions | Component interaction |
| Focus | Compatibility | Correctness | Workflow |
| Speed | Medium | Fast | Slow |
| Dependencies | Real API | None | Multiple services |
| Use case | API validation | Logic testing | E2E scenarios |
Advanced topics
Multiple environments
Test the same contract across environments:Custom validation
Extend validation with custom scripts:Regression prevention
Store test results and compare:Related commands
- simulator test - Full command reference
- simulator validate - Validate contract syntax
- simulator import - Import OpenAPI as contract
Next steps
- Create your first service definition
- Learn about contract-driven development
- Set up CI/CD integration
- Explore compatibility policies