From 1837f62a5f28aa956102c2cf9b0cdeb61d09f2d5 Mon Sep 17 00:00:00 2001 From: Ian Rose Date: Sun, 6 Aug 2023 09:27:23 -0400 Subject: [PATCH] Ensure AssertExpectations does not fail in skipped tests --- mock/mock.go | 3 +++ mock/mock_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/mock/mock.go b/mock/mock.go index 3234436de..1b9e5cd67 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -594,6 +594,9 @@ 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.(interface{ Skipped() bool }); ok && s.Skipped() { + return true + } if h, ok := t.(tHelper); ok { h.Helper() } diff --git a/mock/mock_test.go b/mock/mock_test.go index 77493c55d..9175d05f7 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -1493,6 +1493,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)