Two set of assert and check functions for hard and soft unit test assertions in Go. The golang creators reject to create own testing framework, see Go FAQ about testing framework.
Inspired by:
Improvements:
The check functions are soft assertions. Failing tests will only be reported to the console via t.Errorf(). The assert functions are hard assertions. Failing tests will be reported to the console via t.Failf() and skip the current test execution.
import "https://github.com/vizor-games/golang-unittest/check"
type Person struct {
name string
age int
}
var paul = Person{
name: "Paul",
age: 32,
}
paul2 := paul
func TestEqual(t *testing.T) {
check.Equal(t, paul, paul2, "Paul equals Paul")
}
var peter = Person{
name: "Peter",
age: 21,
}
func TestNotEqual(t *testing.T) {
assert.NotEqual(t, paul, peter, "Paul does not equal Peter")
Use assert.J or check.J to convert args... to []interface{}:
func TestError(t *testing.T) {
// "err is not nil for unexist file"
assert.Error(t, assert.J(os.Open("unexist.file")))
}
New way:
vgo get github.com/vizor-games/golang-unittest
Old way:
go get github.com/vizor-games/golang-unittest
go test -v # -v - verbose
go test ./assert
go test ./check
This project is distributed under the MIT license.
Version | Tag | Published |
---|---|---|
v0.0.0-20181204092023-63cfe0386347 | 2yrs ago |