MCPcopy
hub / github.com/stretchr/testify / Run

Method Run

suite/suite.go:98–117  ·  view source on GitHub ↗

Run provides suite functionality around golang subtests. It should be called in place of t.Run(name, func(t *testing.T)) in test suite code. The passed-in func will be executed as a subtest with a fresh instance of t. Provides compatibility with go test pkg -run TestSuite/TestName/SubTestName.

(name string, subtest func())

Source from the content-addressed store, hash-verified

96// The passed-in func will be executed as a subtest with a fresh instance of t.
97// Provides compatibility with go test pkg -run TestSuite/TestName/SubTestName.
98func (suite *Suite) Run(name string, subtest func()) bool {
99 oldT := suite.T()
100
101 return oldT.Run(name, func(t *testing.T) {
102 suite.SetT(t)
103 defer suite.SetT(oldT)
104
105 defer recoverAndFailOnPanic(t)
106
107 if setupSubTest, ok := suite.s.(SetupSubTest); ok {
108 setupSubTest.SetupSubTest()
109 }
110
111 if tearDownSubTest, ok := suite.s.(TearDownSubTest); ok {
112 defer tearDownSubTest.TearDownSubTest()
113 }
114
115 subtest()
116 })
117}
118
119type test = struct {
120 name string

Callers 7

TestSubtestMethod · 0.45
Test_AMethod · 0.45
Test_BMethod · 0.45
TestSubtestPanicMethod · 0.45
TestUnInitializedSuitesFunction · 0.45
runTestsFunction · 0.45

Calls 5

TMethod · 0.95
SetTMethod · 0.95
recoverAndFailOnPanicFunction · 0.85
SetupSubTestMethod · 0.65
TearDownSubTestMethod · 0.65

Tested by 6

TestSubtestMethod · 0.36
Test_AMethod · 0.36
Test_BMethod · 0.36
TestSubtestPanicMethod · 0.36
TestUnInitializedSuitesFunction · 0.36