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

Function TestMock_WithTest

mock/mock_test.go:310–338  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

308}
309
310func TestMock_WithTest(t *testing.T) {
311 t.Parallel()
312
313 var (
314 mockedService TestExampleImplementation
315 mockedTest MockTestingT
316 )
317
318 mockedService.Test(&mockedTest)
319 mockedService.On("TheExampleMethod", 1, 2, 3).Return(0, nil)
320
321 // Test that on an expected call, the test was not failed
322
323 mockedService.TheExampleMethod(1, 2, 3)
324
325 // Assert that Errorf and FailNow were not called
326 assert.Equal(t, 0, mockedTest.errorfCount)
327 assert.Equal(t, 0, mockedTest.failNowCount)
328
329 // Test that on unexpected call, the mocked test was called to fail the test
330
331 assert.PanicsWithValue(t, mockTestingTFailNowCalled, func() {
332 mockedService.TheExampleMethod(1, 1, 1)
333 })
334
335 // Assert that Errorf and FailNow were called once
336 assert.Equal(t, 1, mockedTest.errorfCount)
337 assert.Equal(t, 1, mockedTest.failNowCount)
338}
339
340func Test_Mock_On_WithPtrArgMatcher(t *testing.T) {
341 t.Parallel()

Callers

nothing calls this directly

Calls 6

EqualFunction · 0.92
PanicsWithValueFunction · 0.92
ReturnMethod · 0.80
TheExampleMethodMethod · 0.65
TestMethod · 0.45
OnMethod · 0.45

Tested by

no test coverage detected