gohamcrest

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

README

gohamcrest - Hamcrest-style matchers for Golang testing

Build Status codebeat badge Coverage Status License GoDoc GitHub release

gohamcrest is Hamcrest-style matchers for Golang testing designed for easy to write test case.

Simple, readable and humanized, also easy to extended.

Help you become an excellent Golang Software Engineer is my believe.

Chinese doc

Installation

Install Go Env Getting Started .Once finished,then enjoy yourself.

gopm get github.com/tevid/gohamcrest -v -g

Or

go get -u github.com/tevid/gohamcrest

PS: Prefer Golang 1.6+

Features

  • Assert.List
  • Assert.Object
  • Assert.String

More feature please respect.

Usage

  • Assert equal
func TestEqual(t *testing.T) {
	Assert(t,2,Equal(2))
	Assert(t,"joe",Equal("joe"))
}
  • Assert not equal
func TestNotEqual(t *testing.T) {
	Assert(t,2,NotEqual(3))
	Assert(t,"joe",NotEqual("joe1"))
}

or

func TestNotEqual(t *testing.T) {
	Assert(t,2,Not(Equal(3)))
	Assert(t,"joe",Not(Equal("joe1")))
}

More usage,check test case please.More info check Wiki .

If you think the tool is good or have any problems,must let me know, contact me by email when feel free or create a issue.

Contribution

License

The project is licensed under the Apache 2 license.

Documentation

Index

Constants

View Source
const (
	EMPTY     = ""
	LOGIC_NOT = " not "
)

Variables

This section is empty.

Functions

func Assert

func Assert(t *testing.T, actual interface{}, matcher Matcher)

Types

type BaseMatcher

type BaseMatcher struct {
	Expected interface{}
	Reason   string
}

func (*BaseMatcher) FailReason

func (this *BaseMatcher) FailReason(actual interface{}) string

func (*BaseMatcher) Match

func (this *BaseMatcher) Match(actual interface{}) bool

func (*BaseMatcher) NegationFailReason

func (this *BaseMatcher) NegationFailReason(actual interface{}) string

type Matcher

type Matcher interface {
	//run match
	Match(actual interface{}) bool

	//get fail reason
	FailReason(actual interface{}) string

	//get negation fail reason
	NegationFailReason(actual interface{}) string
}

func ContainString

func ContainString(expected string) Matcher

func EmptyList

func EmptyList() Matcher

func EndWith

func EndWith(expected string) Matcher

func Equal

func Equal(expected interface{}) Matcher

Create a Matcher for match the actual object is equal excepted object example:

func GreaterThan

func GreaterThan(expected interface{}) Matcher

func GreaterThanOrEquals

func GreaterThanOrEquals(expected interface{}) Matcher

func HasItems

func HasItems(expected interface{}) Matcher

func HasMapValue added in v1.1.0

func HasMapValue(expected interface{}) Matcher

func LessThan

func LessThan(expected interface{}) Matcher

func LessThanOrEquals

func LessThanOrEquals(expected interface{}) Matcher

func NilVal

func NilVal() Matcher

Create a Matcher for match the object is nil or not. example

func Not

func Not(matcher Matcher) Matcher

func NotEqual

func NotEqual(expected interface{}) Matcher

func NotNilVal

func NotNilVal() Matcher

func StartWith

func StartWith(expected string) Matcher

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL