From 045d838fafe6cb227edb9df09417578fdcbe2f85 Mon Sep 17 00:00:00 2001 From: Keynan Pratt Date: Sat, 11 Jan 2020 19:56:59 +1100 Subject: [PATCH] changed dependency to interface, s.t. consumers can easily mock the testing.T type --- suite/suite.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/suite/suite.go b/suite/suite.go index 6195301..18ee564 100644 --- a/suite/suite.go +++ b/suite/suite.go @@ -17,21 +17,29 @@ import ( var allTestsFilter = func(_, _ string) (bool, error) { return true, nil } var matchMethod = flag.String("testify.m", "", "regular expression to select tests of the testify suite to run") +type TestingT interface { + Run(name string, f func(t *testing.T)) bool + Helper() + + Errorf(format string, args ...interface{}) + FailNow() +} + // Suite is a basic testing suite with methods for storing and // retrieving the current *testing.T context. type Suite struct { *assert.Assertions require *require.Assertions - t *testing.T + t TestingT } // T retrieves the current *testing.T context. -func (suite *Suite) T() *testing.T { +func (suite *Suite) T() TestingT { return suite.t } // SetT sets the current *testing.T context. -func (suite *Suite) SetT(t *testing.T) { +func (suite *Suite) SetT(t TestingT) { suite.t = t suite.Assertions = assert.New(t) suite.require = require.New(t)