Documentation ¶
Overview ¶
Package should contains miscellaneous assertions and matchers for making the tests more expresive. The package is not named something like assert to avoid collision with existing packages.
Matchers ¶
This package defines a Matcher interface that other modules can use for defining their own assertions. The Matcher interface is also compatible with Gomega, so any matcher from the latter should work fine.
Essential matchers can be found in the should/to package, so you can access them using to.MATCHER.
Usage ¶
A matcher is an instance of an object that performs a check. The matcher is usually independent of the actual object being matched; if you want to apply a matcher on an actual object you can do it as follows:
should.Expect(t, ACTUAL, MATCHER)
The code above will fail the test if the ACTUAL object fails the MATCHER. If you don't want to fail the test but instead get a boolean value indicating the result of the match you can do:
should.ExpectE(t, ACTUAL, MATCHER)
Negating a matcher is also possible:
should.Refute(t, ACTUAL, MATCHER) ...or should.Expect(t, ACTUAL, to.Not(MATCHER))
Using with Gomega ¶
Any of the Gomega matchers should work fine:
should.Expect(t, 10, gomega.BeNumerically(">", 5)) // true
Ordering of expected and actual ¶
Early testing frameworks originally used the order EXPECTED-ACTUAL, however, reversing the order to ACTUAL-EXPECTED allows for more fluent and expressive assertions. For instance, writing:
should.Expect(t, roses, to.Equal("red"))
Reads much better than:
should.Expect(t, to.Equal("red"), roses)
Index ¶
- func Expect(t cbtest.T, actual interface{}, matcher matcher.Matcher, ...)
- func ExpectE(t cbtest.T, actual interface{}, matcher matcher.Matcher, ...) bool
- func NoError(t cbtest.T, err interface{})
- func NoErrorE(t cbtest.T, err interface{}) bool
- func Refute(t cbtest.T, matcher matcher.Matcher, actual interface{}, ...)
- func RefuteE(t cbtest.T, matcher matcher.Matcher, actual interface{}, ...) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Expect ¶
Expect checks whenever the given actual value passes the matcher. Panics on failure (just like testify/require).
func ExpectE ¶
func ExpectE(t cbtest.T, actual interface{}, matcher matcher.Matcher, labelAndArgs ...interface{}) bool
ExpectE checks whenever the given actual value passes the matcher. Returns boolean to indicate success or failure (just like testify/assert).
func NoError ¶
NoError fails the test if the given value is an error. Useful for ensuring no errors instead of using if err != nil, etc.
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package format includes useful functions for creating error messages.
|
Package format includes useful functions for creating error messages. |
Package to exposes all the core matchers that can be used with the should.Expect[E] functions.
|
Package to exposes all the core matchers that can be used with the should.Expect[E] functions. |