test

package module
v0.0.4-0...-b1ba0b4 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2019 License: MIT Imports: 3 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

test

GoDoc

Package test provides a basic assertion helper for unit tests.

Usage Example

package math

func TestAdd(t *testing.T) {
    a := 5
    b := 3
    c := Add(a, b)

    test.That(t, c).IsEqualTo(8)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assertions

type Assertions struct {
	// contains filtered or unexported fields
}

Assertions defines a number of assertions that can be made about x.

func That

func That(t T, x interface{}) *Assertions

That returns a new *Assertions using the provided *testing.T and subject, x.

func (*Assertions) HasEquivalentSequenceTo

func (a *Assertions) HasEquivalentSequenceTo(y interface{})

HasEquivalentSequenceTo fails the test if the subject, x, does not have the exact same sequence of values as y. Only for slices.

func (*Assertions) IsEqualTo

func (a *Assertions) IsEqualTo(y interface{})

IsEqualTo fails the test if y is not equal to the subject, x.

func (*Assertions) IsFalse

func (a *Assertions) IsFalse()

IsFalse fails the test if the subject, x, is not a boolean, or is true.

func (*Assertions) IsGreaterThan

func (a *Assertions) IsGreaterThan(y interface{})

IsGreaterThan fails the test if the subject, x, is not greater than y.

func (*Assertions) IsGreaterThanOrEqualTo

func (a *Assertions) IsGreaterThanOrEqualTo(y interface{})

IsGreaterThanOrEqualTo fails the test if the subject, x, is not greater than or equal to y.

func (*Assertions) IsLessThan

func (a *Assertions) IsLessThan(y interface{})

IsLessThan fails the test if the subject, x, is not less than y.

func (*Assertions) IsLessThanOrEqualTo

func (a *Assertions) IsLessThanOrEqualTo(y interface{})

IsLessThanOrEqualTo fails the test if the subject, x, is not less than or equal to y.

func (*Assertions) IsNil

func (a *Assertions) IsNil()

IsNil fails the test if the subject, x, is not nil.

func (*Assertions) IsNotEqualTo

func (a *Assertions) IsNotEqualTo(y interface{})

IsNotEqualTo fails the test if y is equal to the subject, x.

func (*Assertions) IsNotNil

func (a *Assertions) IsNotNil()

IsNotNil fails the test if the subject, x, is nil.

func (*Assertions) IsTrue

func (a *Assertions) IsTrue()

IsTrue fails the test if the subject, x, is not a boolean, or is false.

type Recorder

type Recorder struct {
	HelperCallCount int
	DidFail         bool
	FailMessage     string
}

Recorder is a mock implementation of T that is used for unit tests in this package.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder creates a new test recorder.

func (*Recorder) Fatalf

func (r *Recorder) Fatalf(format string, args ...interface{})

Fatalf sets `didFail` to true and sets `failMessage` to the failure message.

func (*Recorder) Helper

func (r *Recorder) Helper()

Helper simply increments `HelperCallCount`.

func (*Recorder) Name

func (*Recorder) Name() string

Name will always return "Recorder".

type T

type T interface {
	Name() string
	Helper()
	Fatalf(format string, args ...interface{})
}

T defines the methods provided by *testing.T that this package uses. It allows for a mock *testing.T to be used in unit tests for this package.

Jump to

Keyboard shortcuts

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