approval_tests
1.7.2, released 7 weeks ago by shodev.live
Approval tests implementation in Dart for snapshot and complex object testing.
What it does
Approval tests provide an alternative to traditional assertions by taking a snapshot of test results (such as long strings, collections, or JSON objects) and comparing them against a saved approved file. If a mismatch occurs, reporters highlight the differences.
AI-written summary of version 1.7.2, based on the package's README and metadata. Report an inaccuracy
Use it when
- Testing objects with complex values, long strings, or many properties
- Verifying complex JSON model outputs against a baseline snapshot
- Running unit tests where exact string or text output comparison is required
Skip it when
- Testing simple primitive equality where standard expect(actual, equals(expected)) is sufficient
- Projects requiring heavy visual/UI golden testing specifically for Flutter widgets (use approval_tests_flutter instead)
Strengths
- Simplifies assertions for large or complex structured outputs
- Supports automatic file generation and CLI-based review workflows
- Includes atomic text writing and strict mode options for CI environments
Weaknesses
- Requires maintaining approved baseline files alongside source or test code
- Depends on correct file naming and path resolution conventions
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 6
Add approval_tests to dev_dependencies/dependencies in pubspec.yaml and configure test files.
Approvals.verify(response, options: const Options(missingApprovedPolicy: MissingApprovedPolicy.writeReceivedAndFail));Alternatives
Packages that do the same job and could replace approval_tests.
- parameterized_test
Run a Dart test multiple times based on provided parameter lists.
71Compare
Works with
Packages commonly used together with approval_tests: ones it builds on, ones built on it, and its own family.
- test_apiapproval_tests depends on itThe user facing API for structuring Dart tests and checking expectations.
- testapproval_tests depends on itA full featured library for writing and running Dart tests across platforms.
- ispectifyapproval_tests depends on itPure-Dart structured logging, tracing, filtering, history, observers, export, and redaction core.
- ispectSame familyIn-app observability and QA diagnostics toolkit with logs, network tracing, and layout inspection.