Skip to content

Commit

Permalink
Remove suite.Suite interface
Browse files Browse the repository at this point in the history
  • Loading branch information
maroux committed Nov 29, 2021
1 parent 06f860b commit 4f5fd9a
Show file tree
Hide file tree
Showing 5 changed files with 321 additions and 346 deletions.
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,9 @@ import (
"github.com/stretchr/testify/suite"
)

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

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

// All methods that begin with "Test" are run as tests within a
// suite.
func (suite *ExampleTestSuite) TestExample() {
assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive)
func (suite *ExampleTestSuite) TestExample(t *suite.T) {
assert.Equal(t, 5, suite.VariableThatShouldStartAtFive)
}

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

// Define the suite, and absorb the built-in basic suite
// functionality from testify - including assertion methods.
// Define the suite, which is simply a struct with all
// fields that tests need.
type ExampleTestSuite struct {
suite.Suite
VariableThatShouldStartAtFive int
}

// Make sure that VariableThatShouldStartAtFive is set to five
// before each test
func (suite *ExampleTestSuite) SetupTest() {
func (suite *ExampleTestSuite) SetupTest(t *suite.T) {
suite.VariableThatShouldStartAtFive = 5
}

// All methods that begin with "Test" are run as tests within a
// suite.
func (suite *ExampleTestSuite) TestExample() {
suite.Equal(suite.VariableThatShouldStartAtFive, 5)
func (suite *ExampleTestSuite) TestExample(t *suite.T) {
t.Equal(5, suite.VariableThatShouldStartAtFive)
}

// In order for 'go test' to run this suite, we need to create
Expand Down
25 changes: 11 additions & 14 deletions suite/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
// or individual tests (depending on which interface(s) you
// implement).
//
// A testing suite is usually built by first extending the built-in
// suite functionality from suite.Suite in testify.
// A testing suite is usually built by defining a Suite struct
// that includes all fields that tests need.
//
// After that, you can implement any of the interfaces in
// suite/interfaces.go to add setup/teardown functionality to your
// suite, and add any methods that start with "Test" to add tests.
// Test methods must match signature: `func(*suite.T)`. The suite.T
// object passed may be used to run sub-tests, verify assertions
// and control test execution.
// Methods that do not match any suite interfaces and do not begin
// with "Test" will not be run by testify, and can safely be used as
// helper methods.
Expand All @@ -20,10 +23,6 @@
// identity that "go test" is already looking for (i.e.
// func(*testing.T)).
//
// To be able to run parallel sub-tests, your testing suite should
// implement "CopySuite". This may or may not be a deepcopy depending
// on the fields in the struct.
//
// Regular expression to select test suites specified command-line
// argument "-run". Regular expression to select the methods
// of test suites specified command-line argument "-m".
Expand All @@ -37,25 +36,23 @@
// "github.com/stretchr/testify/suite"
// )
//
// // Define the suite, and absorb the built-in basic suite
// // functionality from testify - including a T() method which
// // returns the current testing context
// // Define the suite, which is simply a struct with all
// // fields that tests need.
// type ExampleTestSuite struct {
// suite.Suite
// VariableThatShouldStartAtFive int
// }
//
// // Make sure that VariableThatShouldStartAtFive is set to five
// // before each test
// func (suite *ExampleTestSuite) SetupTest() {
// func (suite *ExampleTestSuite) SetupTest(t *suite.T) {
// suite.VariableThatShouldStartAtFive = 5
// }
//
// // All methods that begin with "Test" are run as tests within a
// // suite.
// func (suite *ExampleTestSuite) TestExample() {
// assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive)
// suite.Equal(5, suite.VariableThatShouldStartAtFive)
// func (suite *ExampleTestSuite) TestExample(t *suite.T) {
// assert.Equal(t, 5, suite.VariableThatShouldStartAtFive)
// t.Equal(5, suite.VariableThatShouldStartAtFive)
// }
//
// // In order for 'go test' to run this suite, we need to create
Expand Down
32 changes: 7 additions & 25 deletions suite/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,62 +1,44 @@
package suite

import "testing"

// TestingSuite can store and return the current *testing.T context
// generated by 'go test'.
type TestingSuite interface {
T() *testing.T
setT(*testing.T)
clearT()
}

// CopySuite indicates a copyable struct, deepcopy vs shallow is
// implementation detail of the application.
type CopySuite interface {
// Copy creates a copy of the calling suite object. The returned
// object must be the same concrete type as caller
Copy() TestingSuite
}

// SetupAllSuite has a SetupSuite method, which will run before the
// tests in the suite are run.
type SetupAllSuite interface {
SetupSuite()
SetupSuite(t *T)
}

// SetupTestSuite has a SetupTest method, which will run before each
// test in the suite.
type SetupTestSuite interface {
SetupTest()
SetupTest(t *T)
}

// TearDownAllSuite has a TearDownSuite method, which will run after
// all the tests in the suite have been run.
type TearDownAllSuite interface {
TearDownSuite()
TearDownSuite(t *T)
}

// TearDownTestSuite has a TearDownTest method, which will run after
// each test in the suite.
type TearDownTestSuite interface {
TearDownTest()
TearDownTest(t *T)
}

// BeforeTest has a function to be executed right before the test
// starts and receives the suite and test names as input
type BeforeTest interface {
BeforeTest(suiteName, testName string)
BeforeTest(t *T, suiteName, testName string)
}

// AfterTest has a function to be executed right after the test
// finishes and receives the suite and test names as input
type AfterTest interface {
AfterTest(suiteName, testName string)
AfterTest(t *T, suiteName, testName string)
}

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

0 comments on commit 4f5fd9a

Please sign in to comment.