Coder Social home page Coder Social logo

go-approval-tests's Introduction

ApprovalTests.go

ApprovalTests for go

GoDoc Go Report Card Coverage Status Build and Test

Golden master Verification Library

ApprovalTests allows for easy testing of larger objects, strings and anything else that can be saved to a file (images, sounds, csv, etc...)

Examples

Basic string verification

func TestHelloWorld(t *testing.T) {
	approvals.VerifyString(t, "Hello World!")
}

Store approved files in testdata subfolder

Some people prefer to store their approved files in a subfolder "testdata" instead of in the same folder as the production code. To configure this, add a call to UseFolder to your TestMain:

func TestMain(m *testing.M) {
	UseFolder("testdata")
	os.Exit(m.Run())
}

In Project

Note: ApprovalTests uses approvals to test itself. Therefore there are many examples in the code itself.

JSON

VerifyJSONBytes - Simple Formatting for easy comparison. Also uses the .json file extension

func TestVerifyJSON(t *testing.T) {
	jsonb := []byte("{ \"foo\": \"bar\", \"age\": 42, \"bark\": \"woof\" }")
	VerifyJSONBytes(t, jsonb)
}

Matches file: approvals_test.TestVerifyJSON.received.json

{
  "age": 42,
  "bark": "woof",
  "foo": "bar"
}

Reporters

ApprovalTests becomes much more powerful with reporters. Reporters launch programs on failure to help you understand, fix and approve results.

You can make your own easily, here's an example You can also declare which one to use. Either at the

Method level

r := UseReporter(reporters.NewIntelliJ())
defer r.Close()

Test Level

func TestMain(m *testing.M) {
	r := UseReporter(reporters.NewBeyondCompareReporter())
	defer r.Close()
	UseFolder("testdata")

	os.Exit(m.Run())
}

go-approval-tests's People

Contributors

boumenot avatar isidore avatar josephwoodward avatar emilybache avatar dertseha avatar hjwk avatar mattetti avatar christoffer-gamrath avatar kenhkelly avatar objarni avatar kmcrawford avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.