testingmock

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 6 Imported by: 1

README

# gotestingmock Version Coverage Status Go Report Card GoDoc License FOSSA Status FOSSA Status

A Go library providing mock utilities in order to test your testing libraries.

See samples for usage examples.

Features

  • mock *testing.T through designed interface
  • make assertions for *testing.T methods calls
    • Error, Errorf
    • Fatal, Fatalf
    • FailNow
  • retrieve register cleanup functions

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IT

type IT interface {
	Error(args ...any)
	Errorf(format string, args ...any)
	Fatal(args ...any)
	Fatalf(format string, args ...any)
	FailNow()
	Log(args ...any)
	Logf(format string, args ...any)
	Failed() bool
	Cleanup(f func())
}

IT is an interface wrapper around *testing.T. It also implements the interfaces required by testify's assert, require and mock packages. This is useful for creating mocks of testing.T in order to test tests fixtures and utilities.

type MockedT

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

MockedT is a mock implementation of IT that can be used to test fixtures and utilities.

func New

func New(t IT) *MockedT

New creates a new instance of MockedT.

func (*MockedT) AssertDidNotFailed

func (testState *MockedT) AssertDidNotFailed()

AssertDidNotFailed asserts that no failure methods were called.

func (*MockedT) AssertFailNowHasBeenCalled

func (testState *MockedT) AssertFailNowHasBeenCalled()

AssertFailNowHasBeenCalled asserts that FailNow was called.

func (*MockedT) AssertFailedWithError

func (testState *MockedT) AssertFailedWithError()

AssertFailedWithError asserts that an error method (Error, Errorf) was called.

func (*MockedT) AssertFailedWithErrorMessage

func (testState *MockedT) AssertFailedWithErrorMessage(expectedMessage string)

AssertFailedWithErrorMessage asserts that an error method (Error, Errorf) was called with the expected message.

func (*MockedT) AssertFailedWithFatal

func (testState *MockedT) AssertFailedWithFatal()

AssertFailedWithFatal asserts that a fatal method (Fatal, Fatalf) was called.

func (*MockedT) AssertFailedWithFatalMessage

func (testState *MockedT) AssertFailedWithFatalMessage(expectedMessage string)

AssertFailedWithFatalMessage asserts that a fatal method (Fatal, Fatalf) was called with the expected message.

func (*MockedT) Cleanup

func (testState *MockedT) Cleanup(f func())

Cleanup mocked implementation.

func (*MockedT) Error

func (testState *MockedT) Error(args ...any)

Error mocked implementation.

func (*MockedT) Errorf

func (testState *MockedT) Errorf(format string, args ...any)

Errorf mocked implementation.

func (*MockedT) FailNow

func (testState *MockedT) FailNow()

FailNow mocked implementation.

func (*MockedT) Failed

func (testState *MockedT) Failed() bool

Failed mocked implementation.

func (*MockedT) Fatal

func (testState *MockedT) Fatal(args ...any)

Fatal mocked implementation.

func (*MockedT) Fatalf

func (testState *MockedT) Fatalf(format string, args ...any)

Fatalf mocked implementation.

func (*MockedT) GetCleanups

func (testState *MockedT) GetCleanups() []func()

func (*MockedT) Log

func (testState *MockedT) Log(args ...any)

Log mocked implementation.

func (*MockedT) Logf

func (testState *MockedT) Logf(format string, args ...any)

Logf mocked implementation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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