---
name: snapshot-testing
description: Snapshot testing with insta (Rust) — automatic output capture, review workflow, inline snapshots. Use when testing complex output (JSON, AST, HTML) where writing manual assertions is impractical.
license: MIT
---
## What I doGuide snapshot testing—capture output automatically rather than manually writing
assertions.
## Problem with Traditional Assertions```rust// Tedious for complex outputsassert_eq!(config.timeout, 30);
assert_eq!(config.max_retries, 3);
assert_eq!(config.endpoint, "https://api.example.com");
```
Issues: tedious to write, easy to make mistakes, doesn't show actual output.
## Snapshot Testing```rustuse insta::assert_snapshot;
#[test]
fntest_parsed_config() {
let config =parse_config();
assert_snapshot!(config);
}
```
First run: passes, creates snapshot file. Subsequent runs: compares to saved
snapshot.
## Update Snapshots```bashcargo insta test --accept # Interactivecargo insta accept # Accept all```
## insta (Rust)```toml[dev-dependencies]
insta = "1.40"
```
### Basic Usage```rustuse insta::assert_snapshot;
#[test]
fntest_serialize() {
let value = MyStruct { name: "test".into(), count: 42 };
assert_snapshot!(value);
}
```
### Inline Snapshots```rustuse insta::assert_inline_snapshot;
#[test]
fntest_format() {
let result =format_number(42.0);
assert_inline_snapshot!(result, @"42.00");
}
```
## When to Use### Good Candidates- Serialized output (JSON, YAML, TOML)
- Formatted strings
- Error messages
- Configuration
- Complex data structures
- ASCII waveforms/diagrams
### Bad Candidates- Simple primitives (`assert_eq!(x, 5)` is clearer)
- Random values (timestamps, UUIDs)
- Implementation details
## Best Practices1. **Review snapshots** before accepting
2. **Use descriptive names**: `assert_snapshot!("user_login_success", response)`
3. **Commit snapshots**: They're part of the test suite
4. **Update deliberately**: Use `cargo insta`, don't manually edit
---
Use this skill when testing complex output that would require many assertions.