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())
| 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. |
| 98 | func (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 | |
| 119 | type test = struct { |
| 120 | name string |