Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mockito: how to verify calls on real implementation?

I'd like to verify calls to a logger object, so that the real implementation is still called (so I can see the output during tests).

Something like

verify(logger).error(anyString())
like image 591
IttayD Avatar asked May 20 '11 06:05

IttayD


People also ask

How do you verify that a method is called in Mockito?

Mockito verify() simple example It's the same as calling with times(1) argument with verify method. verify(mockList, times(1)). size(); If we want to make sure a method is called but we don't care about the argument, then we can use ArgumentMatchers with verify method.

Does Mockito spy call real method?

A mock does not call the real method, it is just proxy for actual implementations and used to track interactions with it. A spy is a partial mock, that calls the real methods unless the method is explicitly stubbed. Since Mockito does not mock final methods, so stubbing a final method for spying will not help.

Does Mockito verify use equals?

Mockito verifies argument values in natural java style: by using an equals() method.


1 Answers

you need to use spy to verify invocations on real objects.

like image 122
Kalarani Avatar answered Nov 03 '22 14:11

Kalarani