File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -19,3 +19,16 @@ func New(t *testing.T) *Assertion {
1919
2020 return a
2121}
22+
23+ // Run runs f as a subtest of a called name. It runs f in a separate goroutine
24+ // and blocks until f returns or calls a.Parallel to become a parallel test.
25+ // Run reports whether f succeeded (or at least did not fail before calling t.Parallel).
26+ //
27+ // Run may be called simultaneously from multiple goroutines, but all such calls
28+ // must return before the outer test function for a returns.
29+ func (assertion * Assertion ) Run (name string , f func (a * Assertion )) bool {
30+ return assertion .T .Run (name , func (t * testing.T ) {
31+ subAssertion := New (t )
32+ f (subAssertion )
33+ })
34+ }
Original file line number Diff line number Diff line change @@ -13,3 +13,15 @@ func TestNewAssertion(t *testing.T) {
1313 New (new (testing.T ))
1414 })
1515}
16+
17+ func TestRun (t * testing.T ) {
18+ a := New (t )
19+ isSubTestRun := false
20+
21+ a .Run ("sub test" , func (sub * Assertion ) {
22+ DeepEqualNow (t , sub .Name (), "TestRun/sub_test" )
23+ isSubTestRun = true
24+ })
25+
26+ DeepEqualNow (t , isSubTestRun , true )
27+ }
You can’t perform that action at this time.
0 commit comments