Skip to content

Commit cd1a757

Browse files
committed
Remove suite.Suite interface
1 parent 06f860b commit cd1a757

File tree

5 files changed

+321
-346
lines changed

5 files changed

+321
-346
lines changed

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,9 @@ import (
211211
"github.com/stretchr/testify/suite"
212212
)
213213

214-
// Define the suite, and absorb the built-in basic suite
215-
// functionality from testify - including a T() method which
216-
// returns the current testing context
214+
// Define the suite, which is simply a struct with all
215+
// fields that tests need.
217216
type ExampleTestSuite struct {
218-
suite.Suite
219217
VariableThatShouldStartAtFive int
220218
}
221219

@@ -227,8 +225,8 @@ func (suite *ExampleTestSuite) SetupTest() {
227225

228226
// All methods that begin with "Test" are run as tests within a
229227
// suite.
230-
func (suite *ExampleTestSuite) TestExample() {
231-
assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive)
228+
func (suite *ExampleTestSuite) TestExample(t *suite.T) {
229+
assert.Equal(t, 5, suite.VariableThatShouldStartAtFive)
232230
}
233231

234232
// In order for 'go test' to run this suite, we need to create
@@ -251,23 +249,22 @@ import (
251249
"github.com/stretchr/testify/suite"
252250
)
253251

254-
// Define the suite, and absorb the built-in basic suite
255-
// functionality from testify - including assertion methods.
252+
// Define the suite, which is simply a struct with all
253+
// fields that tests need.
256254
type ExampleTestSuite struct {
257-
suite.Suite
258255
VariableThatShouldStartAtFive int
259256
}
260257

261258
// Make sure that VariableThatShouldStartAtFive is set to five
262259
// before each test
263-
func (suite *ExampleTestSuite) SetupTest() {
260+
func (suite *ExampleTestSuite) SetupTest(t *suite.T) {
264261
suite.VariableThatShouldStartAtFive = 5
265262
}
266263

267264
// All methods that begin with "Test" are run as tests within a
268265
// suite.
269-
func (suite *ExampleTestSuite) TestExample() {
270-
suite.Equal(suite.VariableThatShouldStartAtFive, 5)
266+
func (suite *ExampleTestSuite) TestExample(t *suite.T) {
267+
t.Equal(5, suite.VariableThatShouldStartAtFive)
271268
}
272269

273270
// In order for 'go test' to run this suite, we need to create

suite/doc.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
// or individual tests (depending on which interface(s) you
66
// implement).
77
//
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.
1010
//
1111
// After that, you can implement any of the interfaces in
1212
// suite/interfaces.go to add setup/teardown functionality to your
1313
// 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.
1417
// Methods that do not match any suite interfaces and do not begin
1518
// with "Test" will not be run by testify, and can safely be used as
1619
// helper methods.
@@ -20,10 +23,6 @@
2023
// identity that "go test" is already looking for (i.e.
2124
// func(*testing.T)).
2225
//
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-
//
2726
// Regular expression to select test suites specified command-line
2827
// argument "-run". Regular expression to select the methods
2928
// of test suites specified command-line argument "-m".
@@ -37,25 +36,23 @@
3736
// "github.com/stretchr/testify/suite"
3837
// )
3938
//
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.
4341
// type ExampleTestSuite struct {
44-
// suite.Suite
4542
// VariableThatShouldStartAtFive int
4643
// }
4744
//
4845
// // Make sure that VariableThatShouldStartAtFive is set to five
4946
// // before each test
50-
// func (suite *ExampleTestSuite) SetupTest() {
47+
// func (suite *ExampleTestSuite) SetupTest(t *suite.T) {
5148
// suite.VariableThatShouldStartAtFive = 5
5249
// }
5350
//
5451
// // All methods that begin with "Test" are run as tests within a
5552
// // 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)
5956
// }
6057
//
6158
// // In order for 'go test' to run this suite, we need to create

suite/interfaces.go

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,44 @@
11
package suite
22

3-
import "testing"
4-
5-
// TestingSuite can store and return the current *testing.T context
6-
// generated by 'go test'.
7-
type TestingSuite interface {
8-
T() *testing.T
9-
setT(*testing.T)
10-
clearT()
11-
}
12-
13-
// CopySuite indicates a copyable struct, deepcopy vs shallow is
14-
// implementation detail of the application.
15-
type CopySuite interface {
16-
// Copy creates a copy of the calling suite object. The returned
17-
// object must be the same concrete type as caller
18-
Copy() TestingSuite
19-
}
20-
213
// SetupAllSuite has a SetupSuite method, which will run before the
224
// tests in the suite are run.
235
type SetupAllSuite interface {
24-
SetupSuite()
6+
SetupSuite(t *T)
257
}
268

279
// SetupTestSuite has a SetupTest method, which will run before each
2810
// test in the suite.
2911
type SetupTestSuite interface {
30-
SetupTest()
12+
SetupTest(t *T)
3113
}
3214

3315
// TearDownAllSuite has a TearDownSuite method, which will run after
3416
// all the tests in the suite have been run.
3517
type TearDownAllSuite interface {
36-
TearDownSuite()
18+
TearDownSuite(t *T)
3719
}
3820

3921
// TearDownTestSuite has a TearDownTest method, which will run after
4022
// each test in the suite.
4123
type TearDownTestSuite interface {
42-
TearDownTest()
24+
TearDownTest(t *T)
4325
}
4426

4527
// BeforeTest has a function to be executed right before the test
4628
// starts and receives the suite and test names as input
4729
type BeforeTest interface {
48-
BeforeTest(suiteName, testName string)
30+
BeforeTest(t *T, suiteName, testName string)
4931
}
5032

5133
// AfterTest has a function to be executed right after the test
5234
// finishes and receives the suite and test names as input
5335
type AfterTest interface {
54-
AfterTest(suiteName, testName string)
36+
AfterTest(t *T, suiteName, testName string)
5537
}
5638

5739
// WithStats implements HandleStats, a function that will be executed
5840
// when a test suite is finished. The stats contain information about
5941
// the execution of that suite and its tests.
6042
type WithStats interface {
61-
HandleStats(suiteName string, stats *SuiteInformation)
43+
HandleStats(t *T, suiteName string, stats *SuiteInformation)
6244
}

0 commit comments

Comments
 (0)