gunit

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 8 Imported by: 0

README

SMARTY DISCLAIMER: Subject to the terms of the associated license agreement, this software is freely available for your use. This software is FREE, AS IN PUPPIES, and is a gift. Enjoy your new responsibility. This means that while we may consider enhancement requests, we may or may not choose to entertain requests at our sole and absolute discretion.

GoDoc

gunit (v2)

Installation

$ go get github.com/smarty/gunit/v2

Usage

For users of JetBrains IDEs, here's LiveTemplate you can use for generating the scaffolding for a new fixture:

  • Abbreviation: fixture
  • Description: Generate gunit Fixture boilerplate
  • Template Text:
func Test$NAME$Fixture(t *testing.T) {
    gunit.Run(new($NAME$Fixture), t)
}

type $NAME$Fixture struct {
    *gunit.Fixture
}

func (this *$NAME$Fixture) Setup() {
}

func (this *$NAME$Fixture) Test$END$() {
}

NOTE: Be sure to specify that this LiveTemplate is applicable in Go files.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Options singleton

Options provides the sole entrypoint to the option functions provided by this package.

Functions

func Run

func Run(outerFixture any, t *testing.T, options ...Option)

Run accepts a fixture with Test* methods and optional setup/teardown methods and executes the suite. Fixtures must be struct types which embeds a *gunit.Fixture. Assuming a fixture struct with test methods 'Test1' and 'Test2' execution would proceed as follows:

  1. fixture.SetupSuite()
  2. fixture.Setup()
  3. fixture.Test1()
  4. fixture.Teardown()
  5. fixture.Setup()
  6. fixture.Test2()
  7. fixture.Teardown()
  8. fixture.TeardownSuite()

The methods provided by Options may be supplied to this function to tweak the execution.

Types

type Fixture

type Fixture struct{ TestingT }

func (*Fixture) Print

func (this *Fixture) Print(a ...any)

func (*Fixture) Printf

func (this *Fixture) Printf(f string, a ...any)

func (*Fixture) Println

func (this *Fixture) Println(a ...any)

func (*Fixture) Run

func (this *Fixture) Run(name string, test func(fixture *Fixture))

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

func (this *Fixture) So(actual any, assertion assert.Assertion, expected ...any)

So is a convenience method for reporting assertion failure messages with the many assertion functions found in github.com/smarty/gunit/v2/should. Example: this.So(actual, should.Equal, expected)

type Option

type Option func(*config)

Option is a function that modifies a config. See Options for provided behaviors.

type TestingT

type TestingT interface {
	Cleanup(func())
	Context() context.Context
	Error(args ...any)
	Errorf(format string, args ...any)
	Fail()
	FailNow()
	Failed() bool
	Fatal(args ...any)
	Fatalf(format string, args ...any)
	Helper()
	Log(args ...any)
	Logf(format string, args ...any)
	Name() string
	Output() io.Writer
	Setenv(key, value string)
	Skip(args ...any)
	SkipNow()
	Skipf(format string, args ...any)
	Skipped() bool
	TempDir() string
}

Directories

Path Synopsis
better
Package better provides the same assertions as the should package, but the error returned in failure conditions results in a call to *testing.T.Fatal(), halting the currently running test.
Package better provides the same assertions as the should package, but the error returned in failure conditions results in a call to *testing.T.Fatal(), halting the currently running test.
should/internal/go-diff/diffmatchpatch
Package diffmatchpatch offers robust algorithms to perform the operations required for synchronizing plain text.
Package diffmatchpatch offers robust algorithms to perform the operations required for synchronizing plain text.

Jump to

Keyboard shortcuts

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