gest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2017 License: MIT Imports: 6 Imported by: 0

README

gest

SetUp + TearDown for standard go tests. Allows for before-after wrapping of test cases without having to move away from standard golang test development (a la testify Suite)

Usage

Apply the following in your test package's TestMain:

func TestMain(m *testing.M) {
  code := gest.New("MyTestSuite").
    TestSetUp(setUpFunc).
    TestTearDown(tearDownFunc).
    Run(m)
    
  os.Exit(code)
}

func setUpFunc(t *testing.T) {
  // Do set up here...
}

func tearDownFunc(t *testing.T) {
  // Do tear down here...
}

Supported Builders

Each new gest Suite supports the following:

  • TestSetUp
  • TestTearDown
  • BenchmarkSetUp (runs on every iteration, not a general "before whole case") // See TODO
  • BenchmarkTearDown (runs on every iteration, not a general "after whole case") // See TODO
  • ExampleSetUp
  • ExampleTearDown
  • BenchmarkCaseSetUp
  • BenchmarkCaseTearDown

TODO

  • Test/Benchmark/Example Function name injection into setup/teardown methods (breaks API)

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sample added in v0.5.0

func Sample()

Sample is a fake function that does nothing. It is intended only to serve as an identifier for the ExampleSample() test to use

Example

===================================================

exampleSignature = testMsg
fmt.Printf("During Test : %s\n", exampleSignature)
Output:

During SetUp : SETUP WAS HIT
During Test : TEST WAS HIT
During TearDown : TEARDOWN WAS HIT

Types

type Suite

type Suite struct {
	Name string `json:"name"`
	// contains filtered or unexported fields
}

Suite is a builder type for wrapping test cases with SetUp and TearDown methods

func New

func New(name string) *Suite

New begins a new Suite

func (*Suite) BenchmarkSetUp

func (s *Suite) BenchmarkSetUp(BeforeEachBenchmarkFunc func(*testing.B, string)) *Suite

BenchmarkSetUp adds a Set Up method for Benchmarks Inputs:

  • *testing.B object
  • string representing the Benchmark name

func (*Suite) BenchmarkTearDown

func (s *Suite) BenchmarkTearDown(AfterEachBenchmarkFunc func(*testing.B, string)) *Suite

BenchmarkTearDown adds a Tear Down method for Benchmarks Inputs:

  • *testing.B object
  • string representing the Benchmark name

func (*Suite) ExampleSetUp

func (s *Suite) ExampleSetUp(BeforeEachExampleFunc func(string)) *Suite

ExampleSetUp adds a Set Up method for Examples Inputs:

  • string representing the Example name

func (*Suite) ExampleTearDown

func (s *Suite) ExampleTearDown(AfterEachExampleFunc func(string)) *Suite

ExampleTearDown adds a Tear Down method for Examples Inputs:

  • string representing the Example name

func (*Suite) Run

func (s *Suite) Run(m *testing.M) int

Run takes in a *testing.M object, instruments it according to the builder rules, and runs it. The return integer is the result of the instrumented M's .Run() method.

func (*Suite) TestSetUp

func (s *Suite) TestSetUp(BeforeEachTestFunc func(*testing.T, string)) *Suite

TestSetUp adds a Set Up method for Tests. Inputs:

  • *testing.T object
  • string representing the test name

func (*Suite) TestTearDown

func (s *Suite) TestTearDown(AfterEachTestFunc func(*testing.T, string)) *Suite

TestTearDown adds a Tear Down method for Tests Inputs:

  • *testing.T object
  • string representing the test name

type TestDeps

type TestDeps struct{}

TestDeps is an implementation of the testing.testDeps interface, This is a copy of testing/internal/testdeps/deps.go

func (TestDeps) MatchString

func (TestDeps) MatchString(pat, str string) (result bool, err error)

func (TestDeps) StartCPUProfile

func (TestDeps) StartCPUProfile(w io.Writer) error

func (TestDeps) StopCPUProfile

func (TestDeps) StopCPUProfile()

func (TestDeps) WriteHeapProfile

func (TestDeps) WriteHeapProfile(w io.Writer) error

func (TestDeps) WriteProfileTo

func (TestDeps) WriteProfileTo(name string, w io.Writer, debug int) error

Jump to

Keyboard shortcuts

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