jsonassert alternatives and similar packages
Based on the "Testing Frameworks" category.
Alternatively, view jsonassert alternatives based on common mentions on social networks and blogs.
-
Testify
A toolkit with common assertions and mocks that plays nicely with the standard library -
GoConvey
Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go. -
Looking for Maintainer
Selenium/Webdriver client for Go -
gnomock
Test your code without writing mocks with ephemeral Docker containers ๐ฆ Setup popular services with just a couple lines of code โฑ๏ธ No bash, no yaml, only code ๐ป -
go-vcr
Record and replay your HTTP interactions for fast, deterministic and accurate tests -
testfixtures
Ruby on Rails like test fixtures for Go. Write tests against a real database -
goc
A Comprehensive Coverage Testing System for The Go Programming Language -
embedded-postgres
Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test -
gotest.tools
A collection of packages to augment the go testing package and support common patterns. -
testza
Full-featured test framework for Go! Assertions, fuzzing, input testing, output capturing, and much more! ๐ -
go-testdeep
Extremely flexible golang deep comparison, extends the go testing package, tests HTTP APIs and provides tests suite -
go-carpet
go-carpet - show test coverage in terminal for Go source files -
dbcleaner
Clean database for testing, inspired by database_cleaner for Ruby -
GoSpec
Testing framework for Go. Allows writing self-documenting tests/specifications, and executes them concurrently and safely isolated. [UNMAINTAINED] -
testcase
testcase is an opinionated testing framework to support test driven design. -
assert
:exclamation:Basic Assertion Library used along side native go testing, with building blocks for custom assertions -
gogiven
gogiven - BDD testing framework for go that generates readable output directly from source code -
schema
Quick and easy expression matching for JSON schemas used in requests and responses -
gosuite
Test suites support for standard Go1.7 "testing" by leveraging Subtests feature -
testsql
Generate test data from SQL files before testing and clear it after finished.
Access the most powerful time series database as a service
Do you think we are missing an alternative of jsonassert or a related project?
README
[logo](./logo.png)
jsonassert
is a Go test assertion library for verifying that two representations of JSON are semantically equal.
Usage
Create a new *jsonassert.Asserter
in your test and use this to make assertions against your JSON payloads:
func TestWhatever(t *testing.T) {
ja := jsonassert.New(t)
// find some sort of payload
ja.Assertf(payload, `
{
"name": "%s",
"age": %d,
"skills": [
{ "name": "martial arts", "level": 99 },
{ "name": "intelligence", "level": 100 },
{ "name": "mental fortitude", "level": 4 }
]
}`, "River Tam", 16)
}
You may pass in fmt.Sprintf
arguments after the expected JSON structure.
ja.Assertf()
supports assertions against strings only.
Check for presence only
Some properties of a JSON payload may be difficult to know in advance. E.g. timestamps, UUIDs, or other randomly assigned values.
For these types of values, place the string "<<PRESENCE>>"
as the expected value, and jsonassert
will only verify that this key exists (i.e. the actual JSON has the expected key, and its value is not null
), but this does not check its value.
For example:
func TestWhatever(t *testing.T) {
ja := jsonassert.New(t)
ja.Assertf(`
{
"time": "2019-01-28T21:19:42",
"uuid": "94ae1a31-63b2-4a55-a478-47764b60c56b"
}`, `
{
"time": "<<PRESENCE>>",
"uuid": "<<PRESENCE>>"
}`)
}
The above will pass your test, but:
func TestWhatever(t *testing.T) {
ja := jsonassert.New(t)
ja.Assertf(`
{
"date": "2019-01-28T21:19:42",
"uuid": null
}`, `
{
"time": "<<PRESENCE>>",
"uuid": "<<PRESENCE>>"
}`)
}
The above will fail your tests because the time
key was not present in the actual JSON, and the uuid
was null
.
Docs
You can find the GoDocs for this package here.
Contributing
Contributions are welcome. Please discuss feature requests in an issue before opening a PR.
*Note that all licence references and agreements mentioned in the jsonassert README section above
are relevant to that project's source code only.