MCPcopy
hub / github.com/stretchr/testify / AssertNumberOfCalls

Method AssertNumberOfCalls

mock/mock.go:662–675  ·  view source on GitHub ↗

AssertNumberOfCalls asserts that the method was called expectedCalls times.

(t TestingT, methodName string, expectedCalls int)

Source from the content-addressed store, hash-verified

660
661// AssertNumberOfCalls asserts that the method was called expectedCalls times.
662func (m *Mock) AssertNumberOfCalls(t TestingT, methodName string, expectedCalls int) bool {
663 if h, ok := t.(tHelper); ok {
664 h.Helper()
665 }
666 m.mutex.Lock()
667 defer m.mutex.Unlock()
668 var actualCalls int
669 for _, call := range m.calls() {
670 if call.Method == methodName {
671 actualCalls++
672 }
673 }
674 return assert.Equal(t, expectedCalls, actualCalls, fmt.Sprintf("Expected number of calls (%d) of method %s does not match the actual number of calls (%d).", expectedCalls, methodName, actualCalls))
675}
676
677// AssertCalled asserts that the method was called.
678// It can produce a false result when an argument is a pointer type and the underlying value changed after calling the mocked method.

Callers 1

Calls 3

callsMethod · 0.95
EqualFunction · 0.92
HelperMethod · 0.65

Tested by 1