Categorygithub.com/ThCompiler/ts
modulepackage
0.0.2-alpha
Repository: https://github.com/thcompiler/ts.git
Documentation: pkg.go.dev

# README

Testcases (ts)

About

That is simple wrap testify's Suite to write testcases and run them.

It's some kind of experiment.

Support:

  • Check expected results without error ts.ToTestValuesExpected(expected ...interfaces{}) or ts.TTVE(expected ...interfaces{}).
  • Check expected results with nil error ts.ToTestValuesExpectedWithNilError(expected ...interfaces{}) or ts.TTVEWNE(expected ...interfaces{}).
  • Check expected errors (expected error as last returned parameters) . ts.ToTestErrorExpected(err error) or ts.TTEE(err error)
  • Check panic error ts.ToTestPanicErrorExpected(msg interface{}) or ts.TTPEE(msg interface{}).
  • Check not nil error ts.ToTestCheckErrorExpected() or ts.TTCEE().

Examples

package test

import (
	"testing"
	"github.com/ThCompiler/ts"
)

func sum(a, b int64) int64 {
	return a + b
}

type SumSuite struct {
	ts.TestCasesSuite
}

func (s *SumSuite) TestCorrectNumber() {
	s.RunTest(
		sum,
		ts.TestCase{
			Name:     "Zero With One",
			Args:     ts.TTA(int64(0), int64(1)),
			Expected: ts.TTVE(int64(1)),
		},
		ts.TestCase{
			Name:     "Two With One",
			Args:     ts.TTA(int64(2), int64(1)),
			Expected: ts.TTVE(int64(3)),
		},
		ts.TestCase{
			Name:     "Ten With One",
			Args:     ts.TTA(int64(10), int64(1)),
			Expected: ts.TTVE(int64(11)),
		},
		ts.TestCase{
			Name:     "One With One",
			Args:     ts.TTA(int64(1), int64(1)),
			Expected: ts.TTVE(int64(2)),
		},
	)
}

func TestSumSuite(t *testing.T) {
	suite.Run(t, new(SumSuite))
}

This example is located in the example folder.

Future

  • Add documentation.
  • Add Some feature to work with gmock (now, i has no idea how it will be work and be comfortable for using).
  • Improve the way to set the function under test.

# Packages

No description provided by the author
No description provided by the author

# Functions

RunTest is a function to run test cases for testing function out of TestCasesSuite.
ToTestArgs is a small function to convert a list of args to an array of []interfaces{} It can be easier write ToTestArgs(a, b, c) then []interface{}{a, b, c}.
ToTestCheckErrorExpected is a function to construct test exception with only waiting for the not specified error as the result of the function under test.
ToTestErrorExpected is a function to construct test exception with only waiting for the specified error as the result of the function under test.
ToTestExpected is a function to construct test exception all variant of waiting results of the function under test.
ToTestPanicErrorExpected is a function to construct test exception with only waiting for the panic message as the result of the function under test.
ToTestValuesExpected is a function to construct test exception with only waiting for the specified arguments and no one error as the result of the function under test.
ToTestValuesExpectedWithNilError is a function to construct test exception with only waiting for the specified arguments and nil error as the result of the function under test.
TTA is a wrapper over a function ToTestArgs to shorten its name.
TTCEE is a wrapper over a function ToTestCheckErrorExpected to shorten its name.
TTE is a wrapper over a function ToTestExpected to shorten its name.
TTEE is a wrapper over a function ToTestErrorExpected to shorten its name.
TTPEE is a wrapper over a function ToTestPanicErrorExpected to shorten its name.
TTVE is a wrapper over a function ToTestValuesExpected to shorten its name.
TTVEWNE is a wrapper over a function ToTestValuesExpectedWithNilError to shorten its name.

# Structs

TestCase is a structure describing the test case.
TestCasesSuite is a wrapper over a suite.Suite with added methods for run test cases.
TestErrorExpected is a struct contained info about expected returns of tested function.
TestExpected is a struct contained info about expected returns of tested function.
TestPanicErrorExpected is a struct contained info about the expected panic message of tested function.

# Type aliases

MockTestFunction is a interface of function to initialize mocks for a test case.