shuffler

package
v1.56.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package shuffler primarily provides the Suite struct that functions as a test runner and randomizer when embedded in your test struct. Methods defined on your suite struct will be resolved at runtime, and all tests that start with Test will be run. However, the key thing is that the test resolution will also randomize the order of the tests in the suite.

The shuffler package also supports a command line flag to set the randomization seed. By default it uses time.Now().UnixNano(), but you can also set it by passing in `-shuffler.seed=<int>`. The seed used is always logged in the test output.

Caveat: The shuffler package only works for writing testing.T tests. If you

are writing benchmarks, please do not use this package. Also, it is
strongly recommended to not use this with t.Parallel().

An example:

import (
    "github.com/gobox/pkg/shuffler"
    "github.com/stretchr/testify/assert"
)

// Define your suite struct, and embed it to get the predefined functionality
type YourTestSuite struct {
    shuffler.Suite
    Capacitors []Capacitor
}

// Any method that starts with Test will be run by the test suite, just
// like in the testing package
func (s *YourTestSuite) TestThatWeFluxCapacitors(t *testing.T) {
    f := NewFluxer()
    f.Flux(s.Capacitors)
    for c, _ := range s.Capacitors {
        assert.True(t, c.HasBeenFluxed)
    }
}

// Finally, you have to define one traditional test method to act as the
// equivalent of a TestMain(m *testing.M) function in the testing module
func TestCapacitorSuite(t *testing.T) {
    shuffler.Run(t, new(YourTestSuite))
}

Description: Provides helpers for creating a shuffler test suite

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, suites ...TestSuite)

Run takes test suites and runs all the exported Test* methods in random order.

Types

type TestSuite

type TestSuite interface{}

Jump to

Keyboard shortcuts

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