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:
- check functions
- frendlier error messages, including correct code line from tests
- In function for strings
- Error, NilError functions for functions that returns more than one parameter
- NilErr - short way to check no errors
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.