Documentation ¶
Overview ¶
Package gunit provides "testing" package hooks and convenience functions for writing tests in an xUnit style. See the README file and the examples folder for examples.
Index ¶
- Variables
- func Run(fixture any, t *testing.T, options ...option)
- func RunSequential(fixture any, t *testing.T)
- type Fixture
- func (this *Fixture) Assert(condition bool, messages ...string) bool
- func (this *Fixture) AssertDeepEqual(expected, actual any) bool
- func (this *Fixture) AssertEqual(expected, actual any) bool
- func (this *Fixture) AssertSprintEqual(expected, actual any) bool
- func (this *Fixture) AssertSprintfEqual(expected, actual any, format string) bool
- func (this *Fixture) Error(args ...any)
- func (this *Fixture) Errorf(f string, args ...any)
- func (this *Fixture) Failed() bool
- func (this *Fixture) Name() string
- func (this *Fixture) Print(a ...any)
- func (this *Fixture) Printf(format string, a ...any)
- func (this *Fixture) Println(a ...any)
- func (this *Fixture) Run(name string, test func(fixture *Fixture))
- func (this *Fixture) So(actual any, assert assertion, expected ...any) bool
- func (this *Fixture) T() TestingT
- func (this *Fixture) Write(p []byte) (int, error)
- type TestingT
Constants ¶
This section is empty.
Variables ¶
var Options singleton
Functions ¶
func Run ¶
Run receives an instance of a struct that embeds *Fixture. The struct definition may include Setup*, Teardown*, and Test* methods which will be run as an xUnit-style test fixture.
func RunSequential ¶
RunSequential (like Run) receives an instance of a struct that embeds *Fixture. The fixture is run in much the same way, except that it will not be run in parallel with other fixtures in the same package, nor will test cases of the corresponding fixture be run in parallel with each other.
Deprecated ¶
Use Run(fixture, t, Options.AllSequential()) instead.
Types ¶
type Fixture ¶
type Fixture struct {
// contains filtered or unexported fields
}
Fixture keeps track of test status (failed, passed, skipped) and handles custom logging for xUnit style tests as an embedded field. The Fixture manages an instance of *testing.T. Certain methods defined herein merely forward to calls on the *testing.T:
- Fixture.Error(...) ----> *testing.T.Error
- Fixture.Errorf(...) ---> *testing.T.Errorf
- Fixture.Print(...) ----> *testing.T.Log or fmt.Print
- Fixture.Printf(...) ---> *testing.T.Logf or fmt.Printf
- Fixture.Println(...) --> *testing.T.Log or fmt.Println
- Fixture.Failed() ------> *testing.T.Failed()
- Fixture.fail() --------> *testing.T.Fail()
We don't use these methods much, preferring instead to lean heavily on Fixture.So and the rich set of should-style assertions provided at github.com/smartystreets/assertions/should
func (*Fixture) Assert ¶
Assert tests a boolean which, if not true, marks the current test case as failed and prints the provided message.
func (*Fixture) AssertDeepEqual ¶
func (*Fixture) AssertEqual ¶
func (*Fixture) AssertSprintEqual ¶
func (*Fixture) AssertSprintfEqual ¶
func (*Fixture) Run ¶ added in v1.3.5
Run is analogous to *testing.T.Run and allows for running subtests from test fixture methods (such as for table-driven tests).
func (*Fixture) So ¶
So is a convenience method for reporting assertion failure messages, from the many assertion functions found in github.com/smartystreets/assertions/should. Example: this.So(actual, should.Equal, expected)