99 releases (58 stable)

1.41.1 Oct 31, 2024
1.40.0 Sep 6, 2024
1.39.0 May 15, 2024
1.38.0 Mar 28, 2024
0.7.4 Mar 18, 2019

#2 in Testing

Download history 129254/week @ 2024-08-20 134111/week @ 2024-08-27 143708/week @ 2024-09-03 135088/week @ 2024-09-10 126930/week @ 2024-09-17 143469/week @ 2024-09-24 158926/week @ 2024-10-01 155011/week @ 2024-10-08 176186/week @ 2024-10-15 174224/week @ 2024-10-22 188373/week @ 2024-10-29 172678/week @ 2024-11-05 192725/week @ 2024-11-12 199971/week @ 2024-11-19 176039/week @ 2024-11-26 170479/week @ 2024-12-03

770,099 downloads per month
Used in 1,097 crates (1,046 directly)

Apache-2.0

385KB
10K SLoC

insta: a snapshot testing library for Rust

Build Status Crates.io License rustc 1.51.0 Documentation VSCode Extension

Introduction

Snapshots tests (also sometimes called approval tests) are tests that assert values against a reference value (the snapshot). This is similar to how assert_eq! lets you compare a value against a reference value but unlike simple string assertions, snapshot tests let you test against complex values and come with comprehensive tools to review changes.

Snapshot tests are particularly useful if your reference values are very large or change often.

Example

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

Curious? There is a screencast that shows the entire workflow: watch the insta introduction screencast. Or if you're not into videos, read the 5 minute introduction.

Insta also supports inline snapshots which are stored right in your source file instead of separate files. This is accomplished by the companion cargo-insta tool.

Editor Support

For looking at .snap files there is a vscode extension which can syntax highlight snapshot files, review snapshots and more. It can be installed from the marketplace: view on marketplace.

jump to definition

Diffing

Insta uses similar for all its diffing operations. You can use it independently of insta. You can use the similar-asserts crate to get inline diffs for the standard assert_eq! macro to achieve insta like diffs for regular comparisons:

use similar_asserts::assert_eq;

fn main() {
    let reference = vec![1, 2, 3, 4];
    assert_eq!(reference, (0..4).collect::<Vec<_>>());
}

Sponsor

If you like the project and find it useful you can become a sponsor.

Dependencies

~0.2–8.5MB
~71K SLoC