Skip to content

AssertExpectations should not fail if the test was skipped #1329

@ianrose14

Description

@ianrose14

If you set up a test with something like defer myval.AssertExpectations(t) and then later skip the test (t.Skip()), the AssertExpectations check can still fail your test. I propose that AssertExpectations should check whether the test has already been marked as "skipped" and, if so, return nil (success). Here's the change I'm envisioning:

type tSkipped interface {
	Skipped() 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 {     // <--- START OF PROPOSED NEW CODE
		if s.Skipped() {
			return true
		}
	}                                  // <--- END OF PROPOSED NEW CODE
	if h, ok := t.(tHelper); ok {
		h.Helper()
	}
	m.mutex.Lock()
	defer m.mutex.Unlock()
	[...]
}

If y'all are in agreement with this, I'm very happy to create a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpkg-mockAny issues related to Mock

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions