Library / SDK
mitsuhiko/insta avatar
mitsuhiko/insta

insta: snapshot testing for Rust, and when a .snap file is the wrong answer

A snapshot testing library for rust

2,970 stars162 forksRustApache-2.0

At a glance

What is it?
insta stores reference values in .snap files and adds the review tooling that plain assert_eq! lacks. It suits large or fast-changing reference values, and it is the wrong tool when the output is nondeterministic.
Who is it for?
Adopt insta when your reference values are large, structural, or churn often, and you want the diff review step to live in cargo-insta rather than in a hand-written assertion. Skip it when test output contains timestamps, hashes, or iteration-order-dependent data, because every run then produces a new snapshot and the review step becomes noise.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 4 days ago.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 30, 2026, and from our analysis. They are not legal advice.

Editorial analysis

What insta solves that assert_eq! does not

A snapshot test asserts a value against a stored reference value, the snapshot. The README frames this as similar to how assert_eq! compares a value against a reference, with the difference that snapshot tests handle complex values and ship tools to review changes. That second half is the real subject. assert_eq! gives you a boolean and a panic message; when the value is a 200-line debug dump of a parsed document, the message is not a review artifact. insta writes the actual value to a file, keeps the previous one next to it, and produces a diff. The intended reader is a Rust developer whose test output is large, structural, or changes often enough that hand-maintaining expected strings is a tax. The README says snapshot tests are particularly useful when reference values are very large or change often. Small scalar assertions gain nothing here; the file-per-test overhead is not repaid.

How a snapshot gets written, stored and reviewed

The mechanism is a macro plus a file convention. insta::assert_debug_snapshot! formats the value with Debug and compares it against a stored snapshot. On a mismatch the test fails, and the pending value is kept so the companion tool can show it. The README names cargo-insta as the tool that handles inline snapshots, which live in the source file rather than in a separate .snap file. Diffing is delegated to the similar crate, which the README notes can be used independently; similar-asserts applies the same inline diff style to the standard assert_eq! macro. The repository is a Cargo workspace with the insta crate at the root, cargo-insta as a workspace member, and a vscode-insta directory holding a VS Code extension that syntax highlights .snap files and supports reviewing them. The Makefile shows the test matrix the maintainers run: insta with default features, with all features, with no default features, and with the redactions feature under a single test thread. That last flag is a concrete signal that redactions change shared state, which is worth knowing before you enable it in a parallel test suite.

Installing cargo-insta and running a first snapshot test

Install the companion CLI, which is what handles review and inline snapshots:

bash
cargo install cargo-insta

Write a test using the macro from the README example:

rust
#[test]
fn test_hello_world() {
    insta::assert_debug_snapshot!(vec![1, 2, 3]);
}

Run the suite. On the first run there is no stored snapshot, so the test fails and a pending snapshot is recorded. Then run the review command:

bash
cargo test
cargo insta review

The README points to a screencast and a five minute introduction at insta.rs/docs/quickstart/ for the full workflow. What you should see after accepting is a .snap file next to the test, and a passing suite on the next run. The VS Code extension is installable from the marketplace under the identifier mitsuhiko.insta; the README shows it supporting jump-to-definition from a snapshot back to the test.

Where insta stops being the right tool

Snapshots encode whatever the program produced, including the parts you did not mean to assert. If the value contains a timestamp, a random identifier, a hash map iteration order, or an absolute path, the snapshot is unstable and every run produces a diff. Nothing in the README claims to normalize that automatically. The repository layout does show a redactions feature, and the Makefile runs that feature's tests with --test-threads 1, which tells you redaction handling is stateful enough that the maintainers serialize those tests. Treat redactions as a deliberate configuration step, not a default. The second failure mode is review fatigue. Because accepting a change is a single command, a snapshot suite can be updated without being read, at which point it asserts nothing. That is a process problem insta cannot solve for you. A third boundary: if the value is small and stable, a plain assertion communicates intent better than a file the reader has to open.

insta alternatives and the difference in approach

The README names similar-asserts, from the same author, as the way to get insta-like inline diffs for the standard assert_eq! macro. That is the closest alternative and the difference is architectural: similar-asserts keeps the expected value in the test source and only improves how the mismatch is displayed, so there is no .snap file, no pending snapshot, and no review command. You get a better failure message and keep the assertion inline. insta moves the reference value out of the code and adds a review step that can rewrite it. Choose similar-asserts when the expected value is short enough to read in the test and you want the test file to be the single source of truth. Choose insta when the value is too large to keep inline, or when you want the update to be a reviewed diff rather than a manual edit. The two are not exclusive; a suite can use inline assertions for small values and snapshots for large ones.

Maintenance, releases and the Apache-2.0 licence

The repository is not archived, and the last push was on 2026-09-18. Recent releases are 1.48.0 on 2026-06-11, 1.47.2 on 2026-03-30, and 1.47.1 on 2026-03-29. The versioning is ordinary semver on the 1.x line, so upgrading within 1.x should not require source changes, but the CHANGELOG.md at the repository root is where the project records what actually changed between those tags. For upgrade cost, note that the workspace pins clap to version 4.1 in workspace.dependencies with a comment saying it needs pinning in Cargo.lock because of MSRV, and the Makefile has check-msrv and check-minver targets that verify the minimum supported Rust version and minimal dependency versions. If you build cargo-insta yourself, your toolchain has to satisfy that MSRV. The licence is Apache-2.0, permissive, with the usual patent grant and notice requirements. The README also links a sponsorship page; sponsorship does not change the licence terms. This is not legal advice, and if you redistribute a modified cargo-insta you should read the LICENSE file at the repository root rather than this summary.

Who should adopt insta, and who should not

Adopt it if your Rust tests compare structured output: serialized documents, rendered templates, parser results, CLI help text. The value of the library is proportional to how painful the expected value is to maintain by hand. Do not adopt it for scalar assertions, and do not adopt it for output that varies between runs unless you are prepared to configure redactions and accept the serialized test execution the Makefile implies. The vscode-insta extension is a real part of the workflow rather than an afterthought; if your team does not use VS Code, you lose the jump-to-definition and in-editor review path and fall back to cargo insta review in a terminal. That is workable, but it is the part of the experience the README demonstrates with a GIF, so it is worth knowing which side of that line you are on before standardizing on snapshots.

Editorial conclusion

Adopt insta when your reference values are large, structural, or churn often, and you want the diff review step to live in cargo-insta rather than in a hand-written assertion. Skip it when test output contains timestamps, hashes, or iteration-order-dependent data, because every run then produces a new snapshot and the review step becomes noise. Before committing, verify that the snapshot files are checked into version control, that CI fails on a missing snapshot instead of writing one, and that the .snap files are reviewed in the pull request like any other source change.

Frequently asked questions

What is insta used for in Rust projects?

It is a snapshot testing library. Tests assert a value against a stored reference value, and the companion cargo-insta tool reviews and updates those stored values. The README says it is particularly useful when reference values are very large or change often.

How do I install insta and cargo-insta?

The library is published on crates.io as insta, and the README links its crates.io page. The README names cargo-insta as the companion tool for inline snapshots and review, and it is installed as a Cargo binary.

What is the difference between insta and similar-asserts?

similar-asserts keeps the expected value inline in the test and only improves the diff shown on failure. insta stores the reference value in a separate snapshot and adds a review step that can rewrite it. The README presents similar-asserts as a way to get insta-like diffs for the standard assert_eq! macro.

Official sources

  1. License: Apache-2.0
  2. mitsuhiko/insta on GitHub
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/mitsuhiko-insta.svg)](https://hysenlabs.com/projects/mitsuhiko-insta)