import ( "testing" "github.com/pingcap/check" ) func TestMyFunction(t *testing.T) { c := check.New(t) expected := 5 actual := MyFunction() c.Assert(actual, check.Equals, expected) }
import ( "testing" "errors" "github.com/pingcap/check" ) func TestMyFunction(t *testing.T) { c := check.New(t) err := MyFunction() c.Assert(err, check.NotNil) }In the above code, check.NotNil is used to ensure that the error is not nil. If the error is nil, the test will fail. Overall, the pingcap/check package is a testing library that provides several assertion helpers to simplify the process of writing tests in Go. The library is used extensively in the TiDB project, which is an open-source database that is built on top of distributed technology.