gtest

package module
v0.0.3 Latest Latest
Warning

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

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

README

GTEST

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


gtest 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 gtest with go get
  • Use our example to see how to run your first gotest


Installation

To install gtest, use go get:

go get github.com/jcdotter/gtest

or include the github.com/jcdotter/gtest 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/gtest"
)

func TestYourCode(t *testing.T) {

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

}

Configuration

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

Step 1. Create a new test_file.go

package your_package

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

func TestYourCode(t *testing.T) {

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

    gt := gtest.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 gtest to the latest version, use

go get -u github.com/jcdotter/gtest

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.3"
)

Variables

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

Functions

func PrintTable added in v0.0.3

func PrintTable(data [][]string, header bool)

Types

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 Test

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

func New

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

func (*Test) Equal

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

func (*Test) False

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

func (*Test) NotEqual

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

func (*Test) True

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

Jump to

Keyboard shortcuts

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