Documentation
¶
Overview ¶
Package tbltest implements helper functions to help write table driven tests.
The most common way to use this package is in a test function.
func TestFoo(t testing.T){
type testcase struct {
first string
last string
expected string
}
test := tbltest.Cases(
testcase{
first : "Gautam",
last : "Dey",
expected : "Gautam Dey"
},
)
test.Run(func(tc testcase){
if tc.expected != join(tc.first," ",tc.last) {
t.Errorf("Failed test.")
}
})
}
The function provided to run is called for each testcase in the cases.
If the function provided returns a boolean, the return value will be used to
determine weather or not to continue onto the next testcase.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MyCallerFileLine ¶
func MyCallerFileLine() string
MyCallerFileLine returns the FileLine of the caller of the function that called it :)
Types ¶
type Test ¶
type Test struct {
// InOrder defines weather to run the test case in the order defined or randomly.
// This option is overridden by the tblTest.RunOrder command line flag.
InOrder bool
// The order in which to run these tests. This will be overridden by the Command line flag.
RunOrder string
// contains filtered or unexported fields
}
Test holds the testcases.
func Cases ¶
Cases takes a list of test cases to use for the table driven tests.
The test cases can be any type, as long as they are all the same.
func (*Test) AddCases ¶
AddCases takes a list of test cases to use for the table driven tests. It is added to the current list of tests.
The test cases can be any type, as long as they are ALL the tests are of the same type, this included any tests declared
in the Cases methods to create the test object.
func (*Test) Run ¶
Run calls the given function for each test case. (Note the function may be called again with the same testcase, if the tblTest.RunOrder option is specified.) The function must take one of four forms.
`func (tc $testcase)`
`func (tc $testcase) bool`
`func (idx int, tc $testcase)`
`func (idx int, tc $testcase) bool`