|
5 | 5 | // or individual tests (depending on which interface(s) you |
6 | 6 | // implement). |
7 | 7 | // |
8 | | -// A testing suite is usually built by first extending the built-in |
9 | | -// suite functionality from suite.Suite in testify. |
| 8 | +// A testing suite is usually built by defining a Suite struct |
| 9 | +// that includes all fields that tests need. |
10 | 10 | // |
11 | 11 | // After that, you can implement any of the interfaces in |
12 | 12 | // suite/interfaces.go to add setup/teardown functionality to your |
13 | 13 | // suite, and add any methods that start with "Test" to add tests. |
| 14 | +// Test methods must match signature: `func(*suite.T)`. The suite.T |
| 15 | +// object passed may be used to run sub-tests, verify assertions |
| 16 | +// and control test execution. |
14 | 17 | // Methods that do not match any suite interfaces and do not begin |
15 | 18 | // with "Test" will not be run by testify, and can safely be used as |
16 | 19 | // helper methods. |
|
20 | 23 | // identity that "go test" is already looking for (i.e. |
21 | 24 | // func(*testing.T)). |
22 | 25 | // |
23 | | -// To be able to run parallel sub-tests, your testing suite should |
24 | | -// implement "CopySuite". This may or may not be a deepcopy depending |
25 | | -// on the fields in the struct. |
26 | | -// |
27 | 26 | // Regular expression to select test suites specified command-line |
28 | 27 | // argument "-run". Regular expression to select the methods |
29 | 28 | // of test suites specified command-line argument "-m". |
|
37 | 36 | // "github.com/stretchr/testify/suite" |
38 | 37 | // ) |
39 | 38 | // |
40 | | -// // Define the suite, and absorb the built-in basic suite |
41 | | -// // functionality from testify - including a T() method which |
42 | | -// // returns the current testing context |
| 39 | +// // Define the suite, which is simply a struct with all |
| 40 | +// // fields that tests need. |
43 | 41 | // type ExampleTestSuite struct { |
44 | | -// suite.Suite |
45 | 42 | // VariableThatShouldStartAtFive int |
46 | 43 | // } |
47 | 44 | // |
48 | 45 | // // Make sure that VariableThatShouldStartAtFive is set to five |
49 | 46 | // // before each test |
50 | | -// func (suite *ExampleTestSuite) SetupTest() { |
| 47 | +// func (suite *ExampleTestSuite) SetupTest(t *suite.T) { |
51 | 48 | // suite.VariableThatShouldStartAtFive = 5 |
52 | 49 | // } |
53 | 50 | // |
54 | 51 | // // All methods that begin with "Test" are run as tests within a |
55 | 52 | // // suite. |
56 | | -// func (suite *ExampleTestSuite) TestExample() { |
57 | | -// assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive) |
58 | | -// suite.Equal(5, suite.VariableThatShouldStartAtFive) |
| 53 | +// func (suite *ExampleTestSuite) TestExample(t *suite.T) { |
| 54 | +// assert.Equal(t, 5, suite.VariableThatShouldStartAtFive) |
| 55 | +// t.Equal(5, suite.VariableThatShouldStartAtFive) |
59 | 56 | // } |
60 | 57 | // |
61 | 58 | // // In order for 'go test' to run this suite, we need to create |
|
0 commit comments