Reputation: 45
I am new to mockito... What I am trying to do is to use mockito and System.print out the number of times that a certain method was called...
For example, The numer of times that the Class.doSomething() was called: n times
I guess we need to use verify() or Invocations but I have been searching up about this for hours but have not found any solutions...
Can someone please help me with this?
Thanks!
Upvotes: 0
Views: 2422
Reputation: 74
I don't think you can print a message each time the method is called. You can add the log on the production code or use proxy on the method for add logging layer.
@Mock
private MockedObject mockedObject;
verify(mockedObject,times(2)).doSomething();
Upvotes: 1
Reputation: 66
public class Sample {
public void doSomething();
}
@Test
public void testMockitoTimes {
Sample sample = Mockito.mock(Sample.class);
sample.doSomething(); .....
Mockito.verfiy(sample, Mockito.times(n)).doSomething();
}
Upvotes: 3