Skip to content

Commit

Permalink
Ensure AssertExpectations does not fail in skipped tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ianrose14 committed Jan 27, 2023
1 parent 0ab3ce1 commit 6c66835
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,11 @@ func AssertExpectationsForObjects(t TestingT, testObjects ...interface{}) bool {
// AssertExpectations asserts that everything specified with On and Return was
// in fact called as expected. Calls may have occurred in any order.
func (m *Mock) AssertExpectations(t TestingT) bool {
if s, ok := t.(tSkipped); ok {
if s.Skipped() {
return true
}
}
if h, ok := t.(tHelper); ok {
h.Helper()
}
Expand Down Expand Up @@ -1102,3 +1107,7 @@ var spewConfig = spew.ConfigState{
type tHelper interface {
Helper()
}

type tSkipped interface {
Skipped() bool
}
10 changes: 10 additions & 0 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,16 @@ func Test_Mock_AssertExpectations_With_Repeatability(t *testing.T) {

}

func Test_Mock_AssertExpectations_Skipped_Test(t *testing.T) {

var mockedService = new(TestExampleImplementation)

mockedService.On("Test_Mock_AssertExpectations_Skipped_Test", 1, 2, 3).Return(5, 6, 7)
defer mockedService.AssertExpectations(t)

t.Skip("skipping test to ensure AssertExpectations does not fail")
}

func Test_Mock_TwoCallsWithDifferentArguments(t *testing.T) {

var mockedService = new(TestExampleImplementation)
Expand Down

0 comments on commit 6c66835

Please sign in to comment.