mirror of https://github.com/stretchr/testify.git
Add function to return if all tests in a suite passed
parent
f37e428318
commit
961bfee4b1
|
@ -5,7 +5,6 @@ import "time"
|
||||||
// SuiteInformation stats stores stats for the whole suite execution.
|
// SuiteInformation stats stores stats for the whole suite execution.
|
||||||
type SuiteInformation struct {
|
type SuiteInformation struct {
|
||||||
Start, End time.Time
|
Start, End time.Time
|
||||||
Passed bool
|
|
||||||
TestStats map[string]*TestInformation
|
TestStats map[string]*TestInformation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +20,6 @@ func newSuiteInformation() *SuiteInformation {
|
||||||
|
|
||||||
return &SuiteInformation{
|
return &SuiteInformation{
|
||||||
TestStats: testStats,
|
TestStats: testStats,
|
||||||
Passed: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,3 +34,13 @@ func (s SuiteInformation) end(testName string, passed bool) {
|
||||||
s.TestStats[testName].End = time.Now()
|
s.TestStats[testName].End = time.Now()
|
||||||
s.TestStats[testName].Passed = passed
|
s.TestStats[testName].Passed = passed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s SuiteInformation) Passed() bool {
|
||||||
|
for _, stats := range s.TestStats {
|
||||||
|
if !stats.Passed {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package suite
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPassedReturnsTrueWhenAllTestsPass(t *testing.T) {
|
||||||
|
sinfo := newSuiteInformation()
|
||||||
|
sinfo.TestStats = map[string]*TestInformation{
|
||||||
|
"Test1": {TestName: "Test1", Passed: true},
|
||||||
|
"Test2": {TestName: "Test2", Passed: true},
|
||||||
|
"Test3": {TestName: "Test3", Passed: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.True(t, sinfo.Passed())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPassedReturnsFalseWhenSomeTestFails(t *testing.T) {
|
||||||
|
sinfo := newSuiteInformation()
|
||||||
|
sinfo.TestStats = map[string]*TestInformation{
|
||||||
|
"Test1": {TestName: "Test1", Passed: true},
|
||||||
|
"Test2": {TestName: "Test2", Passed: false},
|
||||||
|
"Test3": {TestName: "Test3", Passed: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.False(t, sinfo.Passed())
|
||||||
|
}
|
|
@ -156,12 +156,7 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if stats != nil {
|
if stats != nil {
|
||||||
passed := !t.Failed()
|
passed := !t.Failed()
|
||||||
|
|
||||||
stats.end(method.Name, passed)
|
stats.end(method.Name, passed)
|
||||||
|
|
||||||
if !passed {
|
|
||||||
stats.Passed = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if afterTestSuite, ok := suite.(AfterTest); ok {
|
if afterTestSuite, ok := suite.(AfterTest); ok {
|
||||||
|
|
|
@ -505,7 +505,7 @@ func TestSuiteWithStats(t *testing.T) {
|
||||||
assert.True(t, suiteWithStats.wasCalled)
|
assert.True(t, suiteWithStats.wasCalled)
|
||||||
assert.NotZero(t, suiteWithStats.stats.Start)
|
assert.NotZero(t, suiteWithStats.stats.Start)
|
||||||
assert.NotZero(t, suiteWithStats.stats.End)
|
assert.NotZero(t, suiteWithStats.stats.End)
|
||||||
assert.True(t, suiteWithStats.stats.Passed)
|
assert.True(t, suiteWithStats.stats.Passed())
|
||||||
|
|
||||||
testStats := suiteWithStats.stats.TestStats["TestSomething"]
|
testStats := suiteWithStats.stats.TestStats["TestSomething"]
|
||||||
assert.NotZero(t, testStats.Start)
|
assert.NotZero(t, testStats.Start)
|
||||||
|
|
Loading…
Reference in New Issue