A snapshot testing library for Go that automatically updates expected values in your test source code.
- Inline Snapshots: Expected values live directly in your test code as string literals
- Automatic Updates: Run tests with
-u/-updateflag or setUPDATE_EXPECT=1environment variable to automatically update expectations - Zero Dependencies: Pure Go implementation with no external dependencies
go get github.com/lijunchen/goexpectWrite tests with empty or placeholder expected values:
package mypackage_test
import (
"testing"
"github.com/lijunchen/goexpect"
)
func TestOutput(t *testing.T) {
goexpect.Expect(t, "Hello,\nWorld!", "") // Start with empty string
}Run the test with the update flag to capture the snapshot:
go test -uThe library will automatically update your source code:
func TestOutput(t *testing.T) {
goexpect.Expect(t, "Hello,\nWorld!", `Hello,
World!`) // Automatically filled in!
}You may also be interested in similar snapshot testing libraries in other programming languages: