Snapshot Testing with Verify
When to Use This Skill
Use snapshot testing when:
- Verifying rendered output (HTML emails, reports, generated code)
- Approving public API surfaces for breaking change detection
- Testing HTTP response bodies and headers
- Validating serialization output
- Catching unintended changes in complex objects
What is Snapshot Testing?
Snapshot testing captures output and compares it against a human-approved baseline:
- First run: Test generates a
.received.file with actual output - Human review: Developer approves it, creating a
.verified.file - Subsequent runs: Test compares output against
.verified.file - Changes detected: Test fails, diff tool shows differences for review
This catches unintended changes while allowing intentional changes through explicit approval.
Installation
Add Verify Package
Configure ModuleInitializer
Create a ModuleInitializer.cs in your test project:
Basic Usage
Simple Object Verification
Creates VerifyUserDto.verified.txt:
String/HTML Verification
Creates VerifyRenderedEmail.verified.html - viewable in browser.
Email Template Testing
Use Verify to catch unintended changes in rendered email templates:
Benefits for email testing:
- Catches CSS/layout regressions
- Detects broken template variables
- Visual review in diff tool
- Version control tracks email changes
API Surface Approval
Prevent accidental breaking changes to public APIs:
Or use the dedicated ApiApprover package:
Creates .verified.txt with full API surface - any change requires explicit approval.
HTTP Response Testing
Scrubbing Dynamic Values
Handle timestamps, GUIDs, and other dynamic content:
Output:
Global Scrubbing
Configure in ModuleInitializer:
File Organization
Recommended Structure
.gitignore
.gitattributes
CI/CD Integration
Fail on Missing Verified Files
GitHub Actions
When to Use Snapshot Testing
Best Practices
DO
DON'T
Integration with MJML Email Testing
See the aspnetcore/transactional-emails skill for the complete pattern:
- MJML templates with
{{variable}}placeholders - Render to HTML with test data
- Snapshot test the rendered output
- Review changes in diff tool before approving
This catches:
- Broken variable substitution
- CSS/layout regressions
- Email client compatibility issues
- Unintended content changes
Resources
- Verify GitHub: https://github.com/VerifyTests/Verify
- Verify.Xunit: https://github.com/VerifyTests/Verify.Xunit
- ApiApprover: https://github.com/JakeGinnivan/ApiApprover
- DiffPlex Integration: https://github.com/VerifyTests/Verify.DiffPlex


