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

# 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

# Packages

No description provided by the author

# Functions

Logical operation:and And(cond1, cond2, ...) And(Empty, True) And(Empty, True, False) */.
CallerInfo returns an array of strings containing the file and line number of each stack frame leading from the current test to the assert call that failed.
Judge is empty.
Equal operation: == Eq(3) Eq("3") Eq("hello").
Fail reports a failed through.
Judge is false.
Numerical operation: > Greater(3).
Numerical operation: >= GreaterEq(3).
No description provided by the author
Numerical operation: < Less(3).
Numerical operation: <= LessEq(3).
No description provided by the author
Judge is nil.
Logical operation:not Not(condition) Not(True) Not(Empty) And(Not(Empty), Not(Nil)).
NOT Equal operation: != NotEq(3) NotEq("3") NotEq("hello").
NotRegexp asserts that a specified regexp does not match a string.
Judge NOT Zero value.
ObjectsAreEqual determines if two objects are considered equal.
ObjectsAreEqualValues gets whether two objects are equal, or if their values are equal.
Logical operation:or Or(cond1, cond2, ...) Or(Empty, True) Or(Empty, True, False).
Regexp asserts that a specified regexp matches a string.
Encapsulation new assertable object with new real value fa := goassert.That(t, "hello world").
Judge is true.
Judge is Zero value.

# Structs

New object The encapsulation real value is an assertable object import "github.com/threeq/goassert" // method one: fa := goassert.That(t, "hello world") // method two: so := goassert.New(t) fa := so.That("hello world").

# Interfaces

TestingT is an interface wrapper around *testing.T.

# Type aliases

Condition type define Custom conditions can be used in assertions.
PanicTestFunc defines a func that should be passed to the assert.Panics and assert.NotPanics methods, and represents a simple func that takes no arguments, and returns nothing.