Ensure TearDownTest is called after Skip

pull/97/head
Jon Gjengset 2014-11-03 17:46:03 -05:00
parent d6577e08ec
commit c1b496c5c9
2 changed files with 15 additions and 9 deletions

View File

@ -58,11 +58,13 @@ func Run(t *testing.T, suite TestingSuite) {
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
setupTestSuite.SetupTest()
}
defer func() {
if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok {
tearDownTestSuite.TearDownTest()
}
suite.SetT(parentT)
}()
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok {
tearDownTestSuite.TearDownTest()
}
suite.SetT(parentT)
},
}
tests = append(tests, test)

View File

@ -69,6 +69,10 @@ func (suite *SuiteTester) TestTwo() {
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
// testify as a test in the suite. This is useful for creating helper
// methods for your tests.
@ -91,11 +95,11 @@ func TestRunSuite(t *testing.T) {
assert.Equal(t, suiteTester.SetupSuiteRunCount, 1)
assert.Equal(t, suiteTester.TearDownSuiteRunCount, 1)
// There are two test methods (TestOne and TestTwo), so the
// SetupTest and TearDownTest methods (which should be run once for
// each test) should have been run twice.
assert.Equal(t, suiteTester.SetupTestRunCount, 2)
assert.Equal(t, suiteTester.TearDownTestRunCount, 2)
// There are three test methods (TestOne, TestTwo, and TestSkip), so
// the SetupTest and TearDownTest methods (which should be run once for
// each test) should have been run three times.
assert.Equal(t, suiteTester.SetupTestRunCount, 3)
assert.Equal(t, suiteTester.TearDownTestRunCount, 3)
// Each test should have been run once.
assert.Equal(t, suiteTester.TestOneRunCount, 1)