Skip to content

Commit c719de3

Browse files
Merge pull request stretchr#1331 from ianrose14/ianrose/assertexpectations-skipped
Ensure AssertExpectations does not fail in skipped tests
2 parents 0e75f99 + 1837f62 commit c719de3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

mock/mock.go

+3
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,9 @@ func AssertExpectationsForObjects(t TestingT, testObjects ...interface{}) bool {
594594
// AssertExpectations asserts that everything specified with On and Return was
595595
// in fact called as expected. Calls may have occurred in any order.
596596
func (m *Mock) AssertExpectations(t TestingT) bool {
597+
if s, ok := t.(interface{ Skipped() bool }); ok && s.Skipped() {
598+
return true
599+
}
597600
if h, ok := t.(tHelper); ok {
598601
h.Helper()
599602
}

mock/mock_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,16 @@ func Test_Mock_AssertExpectations_With_Repeatability(t *testing.T) {
14931493

14941494
}
14951495

1496+
func Test_Mock_AssertExpectations_Skipped_Test(t *testing.T) {
1497+
1498+
var mockedService = new(TestExampleImplementation)
1499+
1500+
mockedService.On("Test_Mock_AssertExpectations_Skipped_Test", 1, 2, 3).Return(5, 6, 7)
1501+
defer mockedService.AssertExpectations(t)
1502+
1503+
t.Skip("skipping test to ensure AssertExpectations does not fail")
1504+
}
1505+
14961506
func Test_Mock_TwoCallsWithDifferentArguments(t *testing.T) {
14971507

14981508
var mockedService = new(TestExampleImplementation)

0 commit comments

Comments
 (0)