test

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2020 License: MIT Imports: 3 Imported by: 1

README

test

Package test provides a thin assertion wrapper around the basic Go testing package.

Usage Example

func TestAddCanSum(t *testing.T) {
    // Arrange.
    expected := 5

    // Act.
    actual := Add(2, 3)

    // Assert.
    test.That(t, actual, is.EqualTo(expected))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func That

func That(t TLike, x interface{}, assertion Assertion)

That is the core function of this package. It accepts a TLike (usually a *testing.T), a subject, x, and an assertion.

Types

type Assertion

type Assertion interface {
	EvaluateFor(x interface{}) *Result
}

Assertion represents a single assertable fact. Assertions are provided as the last parameter to the test.That function. The type *is.Equal is an example of an Assertion.

type MockT

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

MockT is an implementation of TLike that is used to unit test the assertions in this package. It likely has few uses outside of this package.

func NewMockT

func NewMockT() *MockT

NewMockT creates and returns a new, empty MockT.

func (*MockT) DidFail

func (t *MockT) DidFail() bool

DidFail returns true if Fatalf was called at all.

func (*MockT) DidFailWith

func (t *MockT) DidFailWith(pattern string) bool

DidFailWith returns true if Fatalf was called and the regex pattern provided matches the failure message.

func (*MockT) Fatalf

func (t *MockT) Fatalf(format string, args ...interface{})

Fatalf simply formats the provided format and args and then stores the result to later be verified. It can be searched for within the MockT using the DidFailWith method.

func (*MockT) GetFailureMessage

func (t *MockT) GetFailureMessage() string

GetFailureMessage returns the failure message, or any empty string if Fatalf has not been called.

func (*MockT) Helper

func (t *MockT) Helper()

Helper simply does nothing.

func (*MockT) Name

func (t *MockT) Name() string

Name always returns the empty string.

type Result

type Result struct {
	Passed           bool
	ParameterSummary map[string]string
	Detail           string
}

Result represents the result of evaluating an Assertion. It provides information used for error reporting.

func (*Result) AssertPassed

func (r *Result) AssertPassed(t TLike)

AssertPassed will fail the provided TLike with a user-friendly message if the result indicates failure.

type TLike

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

TLike is an interface that defines the methods of a *testing.T that are used by this package. Having this interface allows the assertions in this package to be unit tested as well as function in external unit tests.

Directories

Path Synopsis
verbs
has
is

Jump to

Keyboard shortcuts

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