Documentation
¶
Index ¶
- func TableRun[TGot any, TWant any](t testing.TB, fn TestFunc[TGot, TWant], table Table[TGot, TWant], ...)
- func WithTestLogf(log Logf) stdlib.Option[*TestConfig]
- func WithTestMaxCount(maxCount int) stdlib.Option[*TestConfig]
- func WithTestMaxCountScale(maxCountScale float64) stdlib.Option[*TestConfig]
- func WithTestParallel(parallel bool) stdlib.Option[*TestConfig]
- func WithTestPrecondition(precondition TestPrecondition) stdlib.Option[*TestConfig]
- func WithTestRand(r *rand.Rand) stdlib.Option[*TestConfig]
- type Assert
- func (a *Assert) Equal(got, want any) bool
- func (a *Assert) ErrorEqual(got, want error) bool
- func (a *Assert) False(condition bool, format string, args ...any) bool
- func (a *Assert) Match(got, wantPattern string) bool
- func (a *Assert) NotOK(err error) bool
- func (a *Assert) OK(err error) bool
- func (a *Assert) Panic(got func()) bool
- func (a *Assert) PointerEqual(got, want any) bool
- func (a *Assert) True(condition bool, format string, args ...any) bool
- type Asserter
- type Check
- type Checker
- type Logf
- type Table
- type Test
- func BenchmarkTest(t *testing.B, options ...stdlib.Option[*TestConfig]) *Test
- func FuzzTest(t *testing.F, options ...stdlib.Option[*TestConfig]) *Test
- func IntegrationTest(t *testing.T, options ...stdlib.Option[*TestConfig]) *Test
- func PropertyTest(t testing.TB, options ...stdlib.Option[*TestConfig]) *Test
- func UnitTest(t testing.TB, options ...stdlib.Option[*TestConfig]) *Test
- type TestConfig
- type TestFunc
- type TestPrecondition
- type Testcase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TableRun ¶
func TableRun[TGot any, TWant any]( t testing.TB, fn TestFunc[TGot, TWant], table Table[TGot, TWant], options ...stdlib.Option[*TestConfig], )
TableRun will execute all testcases as unit tests with the given test function.
func WithTestLogf ¶
func WithTestLogf(log Logf) stdlib.Option[*TestConfig]
WithTestLogf sets the config logf.
func WithTestMaxCount ¶
func WithTestMaxCount(maxCount int) stdlib.Option[*TestConfig]
WithTestMaxCount sets the config property testing max count.
func WithTestMaxCountScale ¶
func WithTestMaxCountScale(maxCountScale float64) stdlib.Option[*TestConfig]
WithTestMaxCountScale sets the config property testing max count scale.
func WithTestParallel ¶
func WithTestParallel(parallel bool) stdlib.Option[*TestConfig]
WithTestParallel sets the config parallel.
func WithTestPrecondition ¶
func WithTestPrecondition(precondition TestPrecondition) stdlib.Option[*TestConfig]
WithTestPrecondition sets the config precondition.
func WithTestRand ¶
func WithTestRand(r *rand.Rand) stdlib.Option[*TestConfig]
WithTestRand sets the config rand number generator.
Types ¶
type Assert ¶
type Assert struct {
// contains filtered or unexported fields
}
Assert implements helpers for common assertion patterns.
func (*Assert) ErrorEqual ¶
ErrorEqual fails the test if got is not equal to want for errors.
func (*Assert) PointerEqual ¶
PointerEqual fails the test if got is not equal to want for pointers.
type Asserter ¶
type Asserter interface {
True(condition bool, format string, args ...any) bool
False(condition bool, format string, args ...any) bool
OK(err error) bool
NotOK(err error) bool
Match(got, want string) bool
Equal(got, want any) bool
PointerEqual(got, want any) bool
ErrorEqual(got, want error) bool
Panic(got func()) bool
}
Asserter defines common test assertions.
type Check ¶
type Check struct {
// contains filtered or unexported fields
}
Check implements property testing via the "testing/quick" package.
func (*Check) CheckEqual ¶
CheckEqual fails the test if the check function returns false.
type Logf ¶
Logf is the func called when a boolean condition is not met as part of an assertion. It's responsible for generating output to a user indicating the test failure and either allowing the test to continue or immediately stop execution.
type Test ¶
Test merges the stdlib 'testing.TB' with our test helpers into a single implementation.
By using this 'Test' instead of the `testing` structs (T, B, F) we can automatically handle many common assertion patterns and preconditions for different test types (functional, fuzz, or integration).
func BenchmarkTest ¶
BenchmarkTest creates a new *Benchmark configured for running only "benchmark" tests when the BENCHMARK_TEST environment variable is set.
func FuzzTest ¶
FuzzTest creates a new *Benchmark configured for running only "fuzz" tests when the FUZZ_TEST environment variable is set.
func IntegrationTest ¶
IntegrationTest creates a new *Test configured for running only "integration" tests when the INTEGRATION_TEST environment variable is set.
func PropertyTest ¶
PropertyTest creates a new *Test configured for running only "property" tests.
type TestConfig ¶
type TestConfig struct {
// Logf is called when condition of test assertion is not met.
Logf Logf
// Parallel enables/disables Parallel test execution.
Parallel bool
// Precondition is called before test execution to determine if test should
// be skipped and the reason for it.
Precondition TestPrecondition
// QuickConfig modifies of how quick test (property tests) are executed.
QuickConfig *quick.Config
}
TestConfig defines config options for test.
func NewTestConfig ¶
func NewTestConfig(options ...stdlib.Option[*TestConfig]) (*TestConfig, error)
NewTestConfig creates a new *TestConfig for the given functional opts and sane defaults.
type TestFunc ¶
TestFunc is a function that executes a single test for the given testcase.
Note: The benefit of passing in an isolated function for the test is that we can avoid issues with closures when t.Run(...) is called in parallel with the testcase.
type TestPrecondition ¶
TestPrecondition is a func called prior to test execution to determine if the test should be skipped and the reason for it.
type Testcase ¶
type Testcase[TGot any, TWant any] struct { // Got stores inputs for the testcase. Got TGot // Want stores the expectations for the testcase. Want TWant // WantErr stores the optional error expectation for the testcase. WantErr error // Options are custom options for test execution specific to this case. Options []stdlib.Option[*TestConfig] }
Testcase encapsulates the inputs and expectations of a single testcase.