All Projects → bradleyjkemp → Cupaloy

bradleyjkemp / Cupaloy

Licence: mit
Simple Go snapshot testing

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Cupaloy

Playbook Ios
📘A library for isolated developing UI components and automatically taking snapshots of them.
Stars: ✭ 830 (+533.59%)
Mutual labels:  snapshot, snapshot-testing
Snapshooter
Snapshooter is a snapshot testing tool for .NET Core and .NET Framework
Stars: ✭ 118 (-9.92%)
Mutual labels:  snapshot, snapshot-testing
Syrupy
🥞 The sweeter pytest snapshot plugin
Stars: ✭ 73 (-44.27%)
Mutual labels:  snapshot, snapshot-testing
Verify
Verify is a snapshot tool that simplifies the assertion of complex data models and documents.
Stars: ✭ 210 (+60.31%)
Mutual labels:  snapshot, snapshot-testing
reducer-tester
Utilities for testing redux reducers
Stars: ✭ 19 (-85.5%)
Mutual labels:  snapshot-testing, snapshot
pytest-snapshot
A plugin for snapshot testing with pytest.
Stars: ✭ 68 (-48.09%)
Mutual labels:  snapshot-testing, snapshot
Snap Shot It
Smarter snapshot utility for Mocha and BDD test runners + data-driven testing!
Stars: ✭ 138 (+5.34%)
Mutual labels:  snapshot, snapshot-testing
Snapshot Diff
Diffing snapshot utility for Jest
Stars: ✭ 490 (+274.05%)
Mutual labels:  snapshot, snapshot-testing
Typescript Snapshots Plugin
Snapshots language service support for Typescript
Stars: ✭ 122 (-6.87%)
Mutual labels:  snapshot, snapshot-testing
Babel Test
An opinionated library to make testing babel plugins easier.
Stars: ✭ 79 (-39.69%)
Mutual labels:  snapshot
Btrfs Sxbackup
Incremental btrfs snapshot backups with push/pull support via SSH
Stars: ✭ 105 (-19.85%)
Mutual labels:  snapshot
Cv4pve Barc
Backup And Restore Ceph for Proxmox VE
Stars: ✭ 74 (-43.51%)
Mutual labels:  snapshot
Snapper
Bringing Jest-esque Snapshot testing to C#
Stars: ✭ 85 (-35.11%)
Mutual labels:  snapshot-testing
React Nativeish
React Native / React Native Web Boilerplate
Stars: ✭ 106 (-19.08%)
Mutual labels:  snapshot
Aws Maintenance
Collection of scripts and Lambda functions used for maintaining AWS resources
Stars: ✭ 75 (-42.75%)
Mutual labels:  snapshot
Buffer Components
Buffer's shared collection of React UI components 🤜🤛
Stars: ✭ 120 (-8.4%)
Mutual labels:  snapshot-testing
Criu
Checkpoint/Restore tool
Stars: ✭ 1,389 (+960.31%)
Mutual labels:  snapshot
Odiff
The fastest pixel-by-pixel image visual difference tool in the world.
Stars: ✭ 1,173 (+795.42%)
Mutual labels:  snapshot
Afl Snapshot Lkm
A Linux Kernel Module that implements a fast snapshot mechanism for fuzzing.
Stars: ✭ 97 (-25.95%)
Mutual labels:  snapshot
Amdh
Android Mobile Device Hardening
Stars: ✭ 95 (-27.48%)
Mutual labels:  snapshot

Mascot
Build Status Coverage Status Go Report Card GoDoc

Incredibly simple Go snapshot testing: cupaloy takes a snapshot of your test output and compares it to a snapshot committed alongside your tests. If the values don't match then the test will be failed.

There's no need to manually manage snapshot files: just use the cupaloy.SnapshotT(t, value) function in your tests and cupaloy will automatically find the relevant snapshot file (based on the test name) and compare it with the given value.

Usage

Write a test

Firstly, write a test case generating some output and pass this output to cupaloy.SnapshotT:

func TestParsing(t *testing.T) {
    ast := ParseFile("test_input")

    // check that the result is the same as the last time the snapshot was updated
    // if the result has changed (e.g. because the behaviour of the parser has changed)
    // then the test will be failed with an error containing a diff of the changes
    cupaloy.SnapshotT(t, ast)
}

The first time this test is run, a snapshot will be automatically created (using the github.com/davecgh/go-spew package).

Update a snapshot

When the behaviour of your software changes causing the snapshot to change, this test will begin to fail with an error showing the difference between the old and new snapshots. Once you are happy that the new snapshot is correct (and hasn't just changed unexpectedly), you can save the new snapshot by setting the UPDATE_SNAPSHOTS environment and re-running your tests:

UPDATE_SNAPSHOTS=true go test ./...

This will fail all tests where the snapshot was updated (to stop you accidentally updating snapshots in CI) but your snapshot files will now have been updated to reflect the current output of your code.

Supported formats

Snapshots of test output are generated using the github.com/davecgh/go-spew package which uses reflection to deep pretty-print your test result and so will support almost all the basic types (from simple strings, slices, and maps to deeply nested structs) without issue. The only types whose contents cannot be fully pretty-printed are functions and channels.

The most important property of your test output is that it is deterministic: if your output contains timestamps or other fields which will change on every run, then cupaloy will detect this as a change and so fail the test.

Further Examples

Table driven tests

var testCases = map[string][]string{
    "TestCaseOne": []string{......},
    "AnotherTestCase": []string{......},
    ....
}

func TestCases(t *testing.T) {
    for testName, args := range testCases {
        t.Run(testName, func(t *testing.T) {
            result := functionUnderTest(args...)
            cupaloy.SnapshotT(t, result)
        })
    }
}

Changing output directory

func TestSubdirectory(t *testing.T) {
    result := someFunction()
    snapshotter := cupaloy.New(cupaloy.SnapshotSubdirectory("testdata"))
    err := snapshotter.Snapshot(result)
    if err != nil {
        t.Fatalf("error: %s", err)
    }
}

For further usage examples see basic_test.go and advanced_test.go in the examples/ directory which are both kept up to date and run on CI.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].