Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ func Run(t *testing.T, suite TestingSuite) {
failOnPanic(t, r)
}()

stats.start(method.Name)

if setupTestSuite, ok := suite.(SetupTestSuite); ok {
setupTestSuite.SetupTest()
}
if beforeTestSuite, ok := suite.(BeforeTest); ok {
beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name)
}

stats.start(method.Name)

method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
},
}
Expand Down
36 changes: 36 additions & 0 deletions suite/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,42 @@ func TestSuiteWithStats(t *testing.T) {
assert.False(t, testStats["TestPanic"].Passed)
}

type suiteWithSkipInSetupAndStats struct {
Suite
wasCalled bool
stats *SuiteInformation
}

func (s *suiteWithSkipInSetupAndStats) SetupTest() {
s.T().Skip("skip in setup")
}

func (s *suiteWithSkipInSetupAndStats) HandleStats(_ string, stats *SuiteInformation) {
s.wasCalled = true
s.stats = stats
}

func (s *suiteWithSkipInSetupAndStats) TestSomething() {
s.Fail("should not run")
}

func TestSuiteWithSkipInSetupAndStats(t *testing.T) {
skipSuite := new(suiteWithSkipInSetupAndStats)

testing.RunTests(allTestsFilter, []testing.InternalTest{
{
Name: t.Name() + "/skipSuite",
F: func(t *testing.T) {
Run(t, skipSuite)
},
},
})

assert.True(t, skipSuite.wasCalled, "HandleStats should have been called")
assert.NotNil(t, skipSuite.stats, "stats should not be nil")
assert.NotNil(t, skipSuite.stats.TestStats["TestSomething"], "test stats entry should exist even when skipped in SetupTest")
}

// FailfastSuite will test the behavior when running with the failfast flag
// It logs calls in the callOrder slice which we then use to assert the correct calls were made
type FailfastSuite struct {
Expand Down