# Packages
No description provided by the author
# README
goassert
A fluent test assertion library。Implementation reference testify 和 assertj。
Install
go get github.com/threeq/goassert
Use
- import
goassert
package
import "github.com/threeq/goassert"
- use
goassert
use That
function
func TestExample(t *testing.T) {
a := "你好"
//
goassert.That(t, a).As("xxx").
Equal("你好").
StartsWith("").
EndsWith("").
Len(6).
Contains("").
NotContain("h")
}
or use Assertion
Object
func TestExample(t *testing.T) {
so := goassert.Assertion(t)
a := "hello world"
// do something
so.That(a).As("xxx").
Equal("hello world").
StartsWith("").
EndsWith("").
Len(6).
Contains("").
NotContain("h")
}
Use Condition
Assertion contain common assertions.
But for the complex assertion (such as logical judgment, etc.) is not satisfied, can be implemented using Condition
.
goassert
already contains a common Condition
implementation.
func TestExample(t *testing.T) {
so := goassert.Assertion(t)
a := "hello world"
// do something
so.That(a).
Is(Not(Empty))
}
Use custom condition:
cond1 = func(actual interface{}) (b bool, s string) {
return actual.(string) == "123", "custom Condition"
}
func TestExample(t *testing.T) {
so := goassert.Assertion(t)
a := "hello world"
// do something
so.That(a).Is(cond1)
}