wtrocki / snap-contract-go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SnapContractGo

Golang Unit Testing library to ensuring API/JSON based contracts using snapshots.

Benefits

  • Ignore changing values in snapshots
  • First class API JSON support
  • Extends existing unit and integration tests

How

  1. Compare current and recorded responses from the API
  2. Autoupdate response snapshots for visibility.
  3. Report errors if responses formats doesn't match

Getting started

func TestAPIContract(t *testing.T) {
    var apiResponse interface{}
    // check that the result is the same as the last time the snapshot was updated
    snapcontract.SnapshotT(t, apiResponseast)
}

Update a snapshot

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.

Credits

Fork of https://github.com/bradleyjkemp/cupaloy

About

License:MIT License


Languages

Language:Go 99.8%Language:Makefile 0.2%