gotester

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 12 Imported by: 0

README

GOTESTER

Gotester extends the Stretcher Testify package
(reference https://github.com/stretchr/testify/blob/master/README.md)


Gotester provides clear readouts of tests performed set by the Configurations:

  • PrintTest prints the expected and actual output of every test
  • PrintFail prints the expected and actual output when a test fails
  • PrintTrace prints the location of the test in the test file
  • Truncate limits the data printed to console

Getting Started:

  • Install gotester with go get
  • Use our example to see how to run your first gotest


Installation

To install Gotester, use go get:

go get github.com/jcdotter/gotester

or include the github.com/jcdotter/gotester package as an import in your test file and run:

go mod tidy

Use this template in your code to get started with your first basic test:

package your_package

import (
    "testing"
    gt "github.com/jcdotter/gotester"
)

func TestYourCode(t *testing.T) {

    gt.Assert.True(t, true, "True is true!")

}

Configuration

Configure the settings for the tester using the Gotester.Config struct

Step 1. Create a new test_file.go

package your_package

import (
    "testing"
    "github.com/jcdotter/gotester"
)

func TestYourCode(t *testing.T) {

    config := &gotester.Config{
        PrintTest: true,
        PrintTrace: true,
        PrintDetail: true,
        Msg: "result: %s",
    }

    gt := gotester.New(t, config)

    gt.True(true, "true is true!")

}

Step 2. Run the test in your terminal

$ go test -run TestYourCode

Step 3. Check your terminal output

#0 test 'True' succeeded: result: true is true!
  src:          test_file.TestYourCode line 18
  expected:     true
  actual:       true

Staying up to date

To update Gotester to the latest version, use

go get -u github.com/jcdotter/gotester

Supported go versions

We currently support the most recent major Go versions from 1.19 onward.


License

This project is licensed under the terms of the MIT license.

Documentation

Index

Constants

View Source
const (
	VERSION = "0.0.2"
)

Variables

View Source
var (
	Assert  = &assert.Assertions{}
	Require = &require.Assertions{}
	Suite   = &suite.Suite{}
	Mock    = &mock.Mock{}
)

Functions

This section is empty.

Types

type Assertion

type Assertion struct {
	MsgArgs  any
	Expected any
	Actual   any
}

type Config

type Config struct {
	FailFatal   bool
	PrintTest   bool
	PrintFail   bool
	PrintTrace  bool
	PrintDetail bool
	Truncate    bool
	Msg         string
	// contains filtered or unexported fields
}

type MsgArgs added in v0.0.4

type MsgArgs []any

type Tester

type Tester struct {
	*sync.Mutex
	*Config
	// contains filtered or unexported fields
}

func New

func New(t *testing.T, config *Config) *Tester

func (*Tester) Equal

func (t *Tester) Equal(expected any, actual any, msgArgs ...any) bool

func (*Tester) EqualMany

func (t *Tester) EqualMany(assertions ...Assertion) bool

func (*Tester) False

func (t *Tester) False(actual bool, msgArgs ...any) bool

func (*Tester) FalseMany

func (t *Tester) FalseMany(validations ...Validation) bool

func (*Tester) NotEqual

func (t *Tester) NotEqual(expected any, actual any, msgArgs ...any) bool

func (*Tester) NotEqualMany

func (t *Tester) NotEqualMany(assertions ...Assertion) bool

func (*Tester) True

func (t *Tester) True(actual bool, msgArgs ...any) bool

func (*Tester) TrueMany

func (t *Tester) TrueMany(validations ...Validation) bool

type Validation

type Validation struct {
	MsgArgs any
	Actual  bool
}

Jump to

Keyboard shortcuts

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