mirror of https://github.com/stretchr/testify.git
Merging suite_order_test in suite test, removing anonymous defer func call
parent
e7b6c14305
commit
3c60a0e014
|
@ -114,9 +114,7 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
test := testing.InternalTest{
|
test := testing.InternalTest{
|
||||||
Name: method.Name,
|
Name: method.Name,
|
||||||
F: func(t *testing.T) {
|
F: func(t *testing.T) {
|
||||||
defer func() {
|
defer testsSync.Done()
|
||||||
testsSync.Done()
|
|
||||||
}()
|
|
||||||
parentT := suite.T()
|
parentT := suite.T()
|
||||||
suite.SetT(t)
|
suite.SetT(t)
|
||||||
defer failOnPanic(t)
|
defer failOnPanic(t)
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
package suite
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/rand"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CallOrderSuite struct {
|
|
||||||
Suite
|
|
||||||
callOrder []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *CallOrderSuite) call(method string) {
|
|
||||||
time.Sleep(time.Duration(rand.Intn(300)) * time.Millisecond)
|
|
||||||
s.callOrder = append(s.callOrder, method)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSuiteCallOrder(t *testing.T) {
|
|
||||||
Run(t, new(CallOrderSuite))
|
|
||||||
}
|
|
||||||
func (s *CallOrderSuite) SetupSuite() {
|
|
||||||
s.call("SetupSuite")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *CallOrderSuite) TearDownSuite() {
|
|
||||||
s.call("TearDownSuite")
|
|
||||||
assert.Equal(s.T(), "SetupSuite;SetupTest;Test A;TearDownTest;SetupTest;Test B;TearDownTest;TearDownSuite", strings.Join(s.callOrder, ";"))
|
|
||||||
}
|
|
||||||
func (s *CallOrderSuite) SetupTest() {
|
|
||||||
s.call("SetupTest")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *CallOrderSuite) TearDownTest() {
|
|
||||||
s.call("TearDownTest")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *CallOrderSuite) Test_A() {
|
|
||||||
s.call("Test A")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *CallOrderSuite) Test_B() {
|
|
||||||
s.call("Test B")
|
|
||||||
}
|
|
|
@ -3,7 +3,9 @@ package suite
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -443,3 +445,40 @@ func TestSuiteLogging(t *testing.T) {
|
||||||
assert.NotContains(t, output, "TESTLOGPASS")
|
assert.NotContains(t, output, "TESTLOGPASS")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CallOrderSuite struct {
|
||||||
|
Suite
|
||||||
|
callOrder []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CallOrderSuite) call(method string) {
|
||||||
|
time.Sleep(time.Duration(rand.Intn(300)) * time.Millisecond)
|
||||||
|
s.callOrder = append(s.callOrder, method)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSuiteCallOrder(t *testing.T) {
|
||||||
|
Run(t, new(CallOrderSuite))
|
||||||
|
}
|
||||||
|
func (s *CallOrderSuite) SetupSuite() {
|
||||||
|
s.call("SetupSuite")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CallOrderSuite) TearDownSuite() {
|
||||||
|
s.call("TearDownSuite")
|
||||||
|
assert.Equal(s.T(), "SetupSuite;SetupTest;Test A;TearDownTest;SetupTest;Test B;TearDownTest;TearDownSuite", strings.Join(s.callOrder, ";"))
|
||||||
|
}
|
||||||
|
func (s *CallOrderSuite) SetupTest() {
|
||||||
|
s.call("SetupTest")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CallOrderSuite) TearDownTest() {
|
||||||
|
s.call("TearDownTest")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CallOrderSuite) Test_A() {
|
||||||
|
s.call("Test A")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CallOrderSuite) Test_B() {
|
||||||
|
s.call("Test B")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue