mirror of https://github.com/stretchr/testify.git
Simplify the API by using the new assertion.
parent
e8eaa8ab7a
commit
52f556e421
|
@ -4,11 +4,14 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Suite is a basic testing suite with methods for storing and
|
// Suite is a basic testing suite with methods for storing and
|
||||||
// retrieving the current *testing.T context.
|
// retrieving the current *testing.T context.
|
||||||
type Suite struct {
|
type Suite struct {
|
||||||
|
*assert.Assertions
|
||||||
t *testing.T
|
t *testing.T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +23,7 @@ func (suite *Suite) T() *testing.T {
|
||||||
// SetT sets the current *testing.T context.
|
// SetT sets the current *testing.T context.
|
||||||
func (suite *Suite) SetT(t *testing.T) {
|
func (suite *Suite) SetT(t *testing.T) {
|
||||||
suite.t = t
|
suite.t = t
|
||||||
|
suite.Assertions = assert.New(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run takes a testing suite and runs all of the tests attached
|
// Run takes a testing suite and runs all of the tests attached
|
||||||
|
|
|
@ -20,12 +20,12 @@ type SuiteTester struct {
|
||||||
Suite
|
Suite
|
||||||
|
|
||||||
// Keep counts of how many times each method is run.
|
// Keep counts of how many times each method is run.
|
||||||
SetupSuiteRunCount int
|
SetupSuiteRunCount int
|
||||||
TearDownSuiteRunCount int
|
TearDownSuiteRunCount int
|
||||||
SetupTestRunCount int
|
SetupTestRunCount int
|
||||||
TearDownTestRunCount int
|
TearDownTestRunCount int
|
||||||
TestOneRunCount int
|
TestOneRunCount int
|
||||||
TestTwoRunCount int
|
TestTwoRunCount int
|
||||||
NonTestMethodRunCount int
|
NonTestMethodRunCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,8 @@ func (suite *SuiteTester) TearDownTest() {
|
||||||
func (suite *SuiteTester) TestOne() {
|
func (suite *SuiteTester) TestOne() {
|
||||||
beforeCount := suite.TestOneRunCount
|
beforeCount := suite.TestOneRunCount
|
||||||
suite.TestOneRunCount++
|
suite.TestOneRunCount++
|
||||||
assert.Equal(suite.T(), suite.TestOneRunCount, beforeCount + 1)
|
assert.Equal(suite.T(), suite.TestOneRunCount, beforeCount+1)
|
||||||
|
suite.Equal(suite.TestOneRunCount, beforeCount+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestTwo is another example of a test.
|
// TestTwo is another example of a test.
|
||||||
|
@ -66,6 +67,7 @@ func (suite *SuiteTester) TestTwo() {
|
||||||
beforeCount := suite.TestTwoRunCount
|
beforeCount := suite.TestTwoRunCount
|
||||||
suite.TestTwoRunCount++
|
suite.TestTwoRunCount++
|
||||||
assert.NotEqual(suite.T(), suite.TestTwoRunCount, beforeCount)
|
assert.NotEqual(suite.T(), suite.TestTwoRunCount, beforeCount)
|
||||||
|
suite.NotEqual(suite.TestTwoRunCount, beforeCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NonTestMethod does not begin with "Test", so it will not be run by
|
// NonTestMethod does not begin with "Test", so it will not be run by
|
||||||
|
|
Loading…
Reference in New Issue