goassert
is a simple assertion library for go/golang.
It does not try to do anything fancy and keeps things as simple as possible.
Its primary goal is to make assertions as short and simple as possible.
It also takes advantage of go generics as much as possible to be able to handle as many types as possible
with as fewest assertion methods as possible
go get -t -u github.com/golanglibs/goassert@latest
package yourpackage
import (
"testing",
"github.com/golanglibs/goassert"
)
func Test_1Plus1ShouldEqual2(t *testing.T) {
actual := 1 + 1
expected := 2
goassert.Equal(t, expected, actual)
// on assertion error
// --- FAIL: Test_1Plus1ShouldEqual2 (0.00s)
// module_test.go: 11: Expected 2. Actual: 1
}
True
- asserts the value is trueFalse
- asserts the value is false
Equal
- asserts two values are equal. Values must be comparableNotEqual
- asserts two values are not equal. Values must be comparableDeepEqual
- asserts two values are deeply equal. Internally usesreflect.DeepEqual
. Can be used to assert equality of arrays, slices and mapsNotDeepEqual
- asserts two values are deeply not equal. Internally usesreflect.DeepEqual
. Can be used to assert inequality of arrays, slices and mapsNil
- asserts the value is nilNotNil
- asserts the value is not nilSimilarSlice
- asserts two slices have the same values in any order. The elements must be comparableNotSimilarSlice
- asserts two slices do not have the same values. The elements must be comparable
EmptySlice
- asserts the slice is empty. The assertion will fail if the slice is nilNotEmptySlice
- asserts the slice is not nil or emptySliceLength
- asserts the slice has the specified lengthSliceContains
- asserts the slice contains the specified value. The value must be comparableSliceNotContains
- asserts the slice does not contain the specified value. The value must be comparableEmptyMap
- asserts the map is empty. The assertion will fail if the map is nilNotEmptyMap
- asserts the map is not nil or emptyMapLength
- asserts the map has the specified lengthMapContainsKey
- asserts the map contains the specified key. Key must be comparableMapNotContainsKey
- asserts the map does not contain the specified key. Key must be comparableMapContains
- asserts the map contains the specified key-value pair. Key and value must be comparableMapNotContains
- asserts the map does not contain the specified key-value pair. Key and value must be comparable
Panic
- asserts given function panicsNotPanic
- asserts given function does not panicPanicWithError
- asserts given function panics with the specified errorNotPanicWithError
- asserts given functoin does not panic with the specified error