1// Package suite contains logic for creating testing suite structs 2// and running the methods on those structs as tests. The most useful 3// piece of this package is that you can create setup/teardown methods 4// on your testing suites, which will run before/after the whole suite 5// or individual tests (depending on which interface(s) you 6// implement). 7// 8// A testing suite is usually built by first extending the built-in 9// suite functionality from suite.Suite in testify. Alternatively, 10// you could reproduce that logic on your own if you wanted (you 11// just need to implement the TestingSuite interface from 12// suite/interfaces.go). 13// 14// After that, you can implement any of the interfaces in 15// suite/interfaces.go to add setup/teardown functionality to your 16// suite, and add any methods that start with "Test" to add tests. 17// Methods that do not match any suite interfaces and do not begin 18// with "Test" will not be run by testify, and can safely be used as 19// helper methods. 20// 21// Once you've built your testing suite, you need to run the suite 22// (using suite.Run from testify) inside any function that matches the 23// identity that "go test" is already looking for (i.e. 24// func(*testing.T)). 25// 26// Regular expression to select test suites specified command-line 27// argument "-run". Regular expression to select the methods 28// of test suites specified command-line argument "-m". 29// Suite object has assertion methods. 30// 31// A crude example: 32// // Basic imports 33// import ( 34// "testing" 35// "github.com/stretchr/testify/assert" 36// "github.com/stretchr/testify/suite" 37// ) 38// 39// // Define the suite, and absorb the built-in basic suite 40// // functionality from testify - including a T() method which 41// // returns the current testing context 42// type ExampleTestSuite struct { 43// suite.Suite 44// VariableThatShouldStartAtFive int 45// } 46// 47// // Make sure that VariableThatShouldStartAtFive is set to five 48// // before each test 49// func (suite *ExampleTestSuite) SetupTest() { 50// suite.VariableThatShouldStartAtFive = 5 51// } 52// 53// // All methods that begin with "Test" are run as tests within a 54// // suite. 55// func (suite *ExampleTestSuite) TestExample() { 56// assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive) 57// suite.Equal(5, suite.VariableThatShouldStartAtFive) 58// } 59// 60// // In order for 'go test' to run this suite, we need to create 61// // a normal test function and pass our suite to suite.Run 62// func TestExampleTestSuite(t *testing.T) { 63// suite.Run(t, new(ExampleTestSuite)) 64// } 65package suite 66