Add test for suite Setup/TearDown with Skip

pull/97/head
Jon Gjengset 2014-11-25 19:57:20 -05:00
parent c1b496c5c9
commit 576f6382c0
1 changed files with 30 additions and 1 deletions

View File

@ -2,10 +2,11 @@ package suite
import ( import (
"errors" "errors"
"github.com/stretchr/testify/assert"
"io/ioutil" "io/ioutil"
"os" "os"
"testing" "testing"
"github.com/stretchr/testify/assert"
) )
// This suite is intended to store values to make sure that only // This suite is intended to store values to make sure that only
@ -28,18 +29,36 @@ type SuiteTester struct {
NonTestMethodRunCount int 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 // The SetupSuite method will be run by testify once, at the very
// start of the testing suite, before any tests are run. // start of the testing suite, before any tests are run.
func (suite *SuiteTester) SetupSuite() { func (suite *SuiteTester) SetupSuite() {
suite.SetupSuiteRunCount++ suite.SetupSuiteRunCount++
} }
func (suite *SuiteSkipTester) SetupSuite() {
suite.SetupSuiteRunCount++
suite.T().Skip()
}
// The TearDownSuite method will be run by testify once, at the very // The TearDownSuite method will be run by testify once, at the very
// end of the testing suite, after all tests have been run. // end of the testing suite, after all tests have been run.
func (suite *SuiteTester) TearDownSuite() { func (suite *SuiteTester) TearDownSuite() {
suite.TearDownSuiteRunCount++ suite.TearDownSuiteRunCount++
} }
func (suite *SuiteSkipTester) TearDownSuite() {
suite.TearDownSuiteRunCount++
}
// The SetupTest method will be run before every test in the suite. // The SetupTest method will be run before every test in the suite.
func (suite *SuiteTester) SetupTest() { func (suite *SuiteTester) SetupTest() {
suite.SetupTestRunCount++ suite.SetupTestRunCount++
@ -108,6 +127,16 @@ func TestRunSuite(t *testing.T) {
// Methods that don't match the test method identifier shouldn't // Methods that don't match the test method identifier shouldn't
// have been run at all. // have been run at all.
assert.Equal(t, suiteTester.NonTestMethodRunCount, 0) 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 { type SuiteLoggingTester struct {