Debian Codegraph @

README.md

raw
1 # ApprovalTests.go
2
3 ApprovalTests for [go](https://golang.org/)
4
5 [![GoDoc](https://godoc.org/github.com/approvals/go-approval-tests?status.svg)](https://godoc.org/github.com/approvals/go-approval-tests)
6 [![Go Report Card](https://goreportcard.com/badge/github.com/approvals/go-approval-tests)](https://goreportcard.com/report/github.com/approvals/go-approval-tests)
7 [![Coverage Status](https://codecov.io/gh/approvals/go-approval-tests/graph/badge.svg)](https://codecov.io/gh/approvals/go-approval-tests)
8 [![Build Status](https://travis-ci.org/approvals/go-approval-tests.svg)](https://travis-ci.org/approvals/go-approval-tests)
9
10 # Golden master Verification Library
11
12 ApprovalTests allows for easy testing of larger objects, strings and anything else that can be saved to a file (images, sounds, csv, etc...)
13
14 # Examples
15 ## In Project
16 Note: ApprovalTests uses approvaltests to test itself. Therefore there are many examples in the code itself.
17
18 - [approvals_test.go](approvals_test.go)
19
20 ## JSON
21 VerifyJSONBytes - Simple Formatting for easy comparison. Also uses the .json file extension
22
23 ```go
24 func TestVerifyJSON(t *testing.T) {
25 jsonb := []byte("{ \"foo\": \"bar\", \"age\": 42, \"bark\": \"woof\" }")
26 VerifyJSONBytes(t, jsonb)
27 }
28 ```
29
30 Matches file: approvals_test.TestVerifyJSON.received.json
31
32 ```json
33 {
34 "age": 42,
35 "bark": "woof",
36 "foo": "bar"
37 }
38 ```
39
40 ## Reporters
41 ApprovalTests becomes _much_ more powerful with reporters. Reporters launch programs on failure to help you understand, fix and approve results.
42
43 You can make your own easily, [here's an example](reporters/beyond_compare.go)
44 You can also declare which one to use. Either at the
45
46 ### Method level
47
48 ```go
49 r := UseReporter(reporters.NewIntelliJ())
50 defer r.Close()
51 ```
52
53 ### Test Level
54
55 ```go
56 func TestMain(m *testing.M) {
57 r := UseReporter(reporters.NewBeyondCompareReporter())
58 defer r.Close()
59
60 os.Exit(m.Run())
61 }
62 ```