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

Method AssertCalled

mock/mock.go:679–698  ·  view source on GitHub ↗

AssertCalled asserts that the method was called. It can produce a false result when an argument is a pointer type and the underlying value changed after calling the mocked method.

(t TestingT, methodName string, arguments ...interface{})

Source from the content-addressed store, hash-verified

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.
679func (m *Mock) AssertCalled(t TestingT, methodName string, arguments ...interface{}) bool {
680 if h, ok := t.(tHelper); ok {
681 h.Helper()
682 }
683 m.mutex.Lock()
684 defer m.mutex.Unlock()
685 if !m.methodWasCalled(methodName, arguments) {
686 var calledWithArgs []string
687 for _, call := range m.calls() {
688 calledWithArgs = append(calledWithArgs, fmt.Sprintf("%v", call.Arguments))
689 }
690 if len(calledWithArgs) == 0 {
691 return assert.Fail(t, "Should have called with given arguments",
692 fmt.Sprintf("Expected %q to have been called with:\n%v\nbut no actual calls happened", methodName, arguments))
693 }
694 return assert.Fail(t, "Should have called with given arguments",
695 fmt.Sprintf("Expected %q to have been called with:\n%v\nbut actual calls were:\n %v", methodName, arguments, strings.Join(calledWithArgs, "\n")))
696 }
697 return true
698}
699
700// AssertNotCalled asserts that the method was not called.
701// It can produce a false result when an argument is a pointer type and the underlying value changed after calling the mocked method.

Calls 4

methodWasCalledMethod · 0.95
callsMethod · 0.95
FailFunction · 0.92
HelperMethod · 0.65