goassertions
Assertions for use in go unit testing, currently only implementing an Equal assertion that compares two variables of any type. Lets you bundle several assertions inside single test function without many if-statements
How to use
Instead of the standard way, implement your test function like the following:
import (
"testing"
assert "github.com/morngrar/goassertions"
)
func TestYourFunc(t testing.T) {
assert.Equal(YourFunc(params), expectedValue, "YourFunc should return X")
...
if assert.Failures() { // some assertion failed
t.Error("YourFunc assertions failed")
}
}
The test output on failures might look like this:
YourFunc should return X, got Y
[...]
--- FAIL: TestYourFunc (0.00s)
youstuff_test.go:14: YourFunc assertions failed
FAIL
exit status 1
FAIL yourstuff 0.003s
Contributing
PRs implementing further assertions or other improvements are welcome; however, tests are a requirement. At least cover your code as well as the existing Equal function.