From 576f6382c0039179b0b6b923c682d912a8cf60b0 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Tue, 25 Nov 2014 19:57:20 -0500 Subject: [PATCH] Add test for suite Setup/TearDown with Skip --- suite/suite_test.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/suite/suite_test.go b/suite/suite_test.go index f0fe329..0108123 100644 --- a/suite/suite_test.go +++ b/suite/suite_test.go @@ -2,10 +2,11 @@ package suite import ( "errors" - "github.com/stretchr/testify/assert" "io/ioutil" "os" "testing" + + "github.com/stretchr/testify/assert" ) // This suite is intended to store values to make sure that only @@ -28,18 +29,36 @@ type SuiteTester struct { NonTestMethodRunCount int } +type SuiteSkipTester struct { + // Include our basic suite logic. + Suite + + // Keep counts of how many times each method is run. + SetupSuiteRunCount int + TearDownSuiteRunCount int +} + // The SetupSuite method will be run by testify once, at the very // start of the testing suite, before any tests are run. func (suite *SuiteTester) SetupSuite() { suite.SetupSuiteRunCount++ } +func (suite *SuiteSkipTester) SetupSuite() { + suite.SetupSuiteRunCount++ + suite.T().Skip() +} + // The TearDownSuite method will be run by testify once, at the very // end of the testing suite, after all tests have been run. func (suite *SuiteTester) TearDownSuite() { suite.TearDownSuiteRunCount++ } +func (suite *SuiteSkipTester) TearDownSuite() { + suite.TearDownSuiteRunCount++ +} + // The SetupTest method will be run before every test in the suite. func (suite *SuiteTester) SetupTest() { suite.SetupTestRunCount++ @@ -108,6 +127,16 @@ func TestRunSuite(t *testing.T) { // Methods that don't match the test method identifier shouldn't // have been run at all. assert.Equal(t, suiteTester.NonTestMethodRunCount, 0) + + suiteSkipTester := new(SuiteSkipTester) + Run(t, suiteSkipTester) + + // The suite was only run once, so the SetupSuite and TearDownSuite + // methods should have each been run only once, even though SetupSuite + // called Skip() + assert.Equal(t, suiteSkipTester.SetupSuiteRunCount, 1) + assert.Equal(t, suiteSkipTester.TearDownSuiteRunCount, 1) + } type SuiteLoggingTester struct {