mirror of
https://github.com/stretchr/testify.git
synced 2025-05-31 11:42:44 +00:00
Ensure TearDownTest is called after Skip
This commit is contained in:
parent
d6577e08ec
commit
c1b496c5c9
@ -58,11 +58,13 @@ func Run(t *testing.T, suite TestingSuite) {
|
|||||||
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
|
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
|
||||||
setupTestSuite.SetupTest()
|
setupTestSuite.SetupTest()
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok {
|
||||||
|
tearDownTestSuite.TearDownTest()
|
||||||
|
}
|
||||||
|
suite.SetT(parentT)
|
||||||
|
}()
|
||||||
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
|
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
|
||||||
if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok {
|
|
||||||
tearDownTestSuite.TearDownTest()
|
|
||||||
}
|
|
||||||
suite.SetT(parentT)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tests = append(tests, test)
|
tests = append(tests, test)
|
||||||
|
@ -69,6 +69,10 @@ func (suite *SuiteTester) TestTwo() {
|
|||||||
suite.NotEqual(suite.TestTwoRunCount, beforeCount)
|
suite.NotEqual(suite.TestTwoRunCount, beforeCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *SuiteTester) TestSkip() {
|
||||||
|
suite.T().Skip()
|
||||||
|
}
|
||||||
|
|
||||||
// NonTestMethod does not begin with "Test", so it will not be run by
|
// NonTestMethod does not begin with "Test", so it will not be run by
|
||||||
// testify as a test in the suite. This is useful for creating helper
|
// testify as a test in the suite. This is useful for creating helper
|
||||||
// methods for your tests.
|
// methods for your tests.
|
||||||
@ -91,11 +95,11 @@ func TestRunSuite(t *testing.T) {
|
|||||||
assert.Equal(t, suiteTester.SetupSuiteRunCount, 1)
|
assert.Equal(t, suiteTester.SetupSuiteRunCount, 1)
|
||||||
assert.Equal(t, suiteTester.TearDownSuiteRunCount, 1)
|
assert.Equal(t, suiteTester.TearDownSuiteRunCount, 1)
|
||||||
|
|
||||||
// There are two test methods (TestOne and TestTwo), so the
|
// There are three test methods (TestOne, TestTwo, and TestSkip), so
|
||||||
// SetupTest and TearDownTest methods (which should be run once for
|
// the SetupTest and TearDownTest methods (which should be run once for
|
||||||
// each test) should have been run twice.
|
// each test) should have been run three times.
|
||||||
assert.Equal(t, suiteTester.SetupTestRunCount, 2)
|
assert.Equal(t, suiteTester.SetupTestRunCount, 3)
|
||||||
assert.Equal(t, suiteTester.TearDownTestRunCount, 2)
|
assert.Equal(t, suiteTester.TearDownTestRunCount, 3)
|
||||||
|
|
||||||
// Each test should have been run once.
|
// Each test should have been run once.
|
||||||
assert.Equal(t, suiteTester.TestOneRunCount, 1)
|
assert.Equal(t, suiteTester.TestOneRunCount, 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user