Overview
Approval Tests is a testing approach in Dart that verifies output by comparing it against approved reference files. Inspired by the ApprovalTests pattern, it simplifies testing complex or structured data—like JSON, HTML, or logs—by automatically capturing and validating expected outputs. Developers write tests that generate output, which is then reviewed and 'approved' as correct. Future test runs compare new output against the approved version, flagging discrepancies. It's particularly useful for reducing boilerplate in integration and end-to-end tests.
Use cases
- Verifying complex output like JSON or HTML
- Validating UI snapshots
- Testing API responses
- Automating regression testing
- Reviewing log outputs
Key features
- Automatic output approval workflow
- Supports multiple output formats
- Easy integration with existing test suites
- Visual diffing of changes
- Simple setup with minimal code
Suitable for
- Testers working with structured data
- Teams using regression testing
- Developers seeking low-maintenance test validation
- Projects with frequent output changes
- CI/CD pipelines requiring reliable output checks
Considerations
- Requires manual approval of first-run output
- File-based storage may increase repository size
- Not ideal for highly dynamic or randomized data
- Needs careful handling in shared CI environments
- Approvals must be reviewed before merging