snapshot

package module
v0.0.0-...-52db41d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 10 Imported by: 0

README

Snapshot

Package snapshot implements snapshot testing for Go.

It works by modifying the test file itself during execution.

Installation

go get github.com/aarol/snapshot

Example

  • Step 1: Call the MatchesInline function inside your tests:
package snapshot_test

import (
	"testing"

	"github.com/aarol/snapshot"
)

func TestSnapshot(t *testing.T) {
	val := 1
	snapshot.MatchesInline(t, val)

	val2 := "123"
	snapshot.MatchesInline(t, val2)
}
  • Step 2: Run the tests with go test and observe the added parameters:

func TestSnapshot(t *testing.T) {
	val := 1
	snapshot.MatchesInline(t, val, 1)

	val2 := "123"
	snapshot.MatchesInline(t, val2, "123")
}

Now, any future values of val or val2 will be compared against the hard-coded value. If it were to change, the test would error:

> go test .

--- FAIL: TestSnapshot (0.00s)
    snapshot_test.go:11: snapshot doesn't match: want 1, got 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchesInline

func MatchesInline(t *testing.T, values ...any)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL