Documentation
¶
Index ¶
- func FieldValue[T any](tc any, k reflect.Kind, result func(v reflect.Value) T, fields ...string) (T, bool)
- func IsDebugging(tc any) bool
- func IsSkipping(tc any) bool
- func NameOrDefault(tc any, n string, i int) string
- type AnonCaseExecution
- type Controller
- type Executor
- type Flags
- type NamedCaseExecution
- type Registration
- type Runner
- type TestExecutor
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldValue ¶
func FieldValue[T any]( tc any, k reflect.Kind, result func(v reflect.Value) T, fields ...string, ) (T, bool)
FieldValue retrieves a field value of a specified type (reflect.Kind) from a struct or pointer to a struct.
It checks for the specified field names and returns the value if found using a supplied function to obtain the value from the field ref.
func IsDebugging ¶
IsDebugging returns true if the specified test case is a struct with a bool debug/Debug field that is set true, otherwise it returns false.
func IsSkipping ¶
IsSkipping returns true if the specified test case is a struct with a bool skip/Skip field that is set true, otherwise it returns false.
func NameOrDefault ¶
NameOrDefault derives a name for a given test case. If a name (n) is given, it is used without checking the test case.
If no name is given and the test case is a struct with a string field named "Scenario", "scenario", "NameOrDefault", or "name", then this field is used as the name (if not empty or whitespace).
If the test case is not a struct, has no name field or has a name which is empty, a default name in the format "testcase-NNN" where NNN is the index (i) of the scenario.
Types ¶
type AnonCaseExecution ¶
type AnonCaseExecution[T any] func(tc T)
AnonCaseExecution[T] is a function type that takes a pointer to a test case of type T without a name.
type Controller ¶
type Controller[T any] struct { // contains filtered or unexported fields }
func NewController ¶
func NewController[T any](data T, index int, name string) Controller[T]
type Executor ¶
type Executor[T any] struct { // contains filtered or unexported fields }
func NewExecutor ¶
type Flags ¶
type Flags int
const ( // NoFlags indicates that no flags are set for the test case NoFlags Flags = 0 // Parallel indicates that the test case should be run in parallel Parallel Flags = 1 // Debug indicates that the test case is a debug target Debug Flags = 2 // Skip indicates that the test case should be skipped Skip Flags = 4 )
type NamedCaseExecution ¶
NamedCaseExecution[T] is a function type that takes a test case name and a pointer to a test case of type T.
type Registration ¶
type Runner ¶
type Runner[T any] struct { TestingT TestExecutor[T] CaseControllers []Controller[T] }
Runner[T] is a struct that holds a testing.T interface, a test executor, a setup controller, and a list of case controllers, used for executing a number of test cases of type T.
It provides methods to configure setup functions and add and run test cases.
func NewRunner ¶
func NewRunner[T any](exec TestExecutor[T]) Runner[T]
NewRunner creates a new Runner instance with the provided test executor
func (*Runner[T]) AddCase ¶
AddCase adds a test case to the runner. The name is used to identify the test case in the test output. The tc provides the data for the test case.
If the name is an empty or whitespace string, a name will be determined as follows:
- if the test case data is a struct (or pointer to a struct) and has a string field named "Scenario", "scenario", "Name", or "name", with a non-empty or whitespace value, that will be used as the name. Otherwise a default name is derived in the format "testcase-NNN" where NNN is the 1-based index of the test case in the list of test cases.
If the test case data has a bool debug/Debug field that is set true, the test case will be marked as a debug test case.
If the test case data has a bool skip/Skip field that is set true, the test case will be marked as a skip test case.
type TestExecutor ¶
TestExecutor[T] is an interface that defines a method to execute an individual test case of type T.