Categorygithub.com/threeq/goassert
repositorypackage
0.0.1
Repository: https://github.com/threeq/goassert.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

goassert

Build Status codecov

A fluent test assertion library。Implementation reference testifyassertj

Install

go get github.com/threeq/goassert

Use

  1. import goassert package
import "github.com/threeq/goassert"
  1. 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)
}

Example