Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable Mockito debug messages?

How do I enable Mockito debug messages? In particular, I'd like print the details of methods stubbed with when() and every interaction with those methods.

like image 505
Derek Mahar Avatar asked Aug 03 '12 19:08

Derek Mahar


People also ask

How do you debug a mock?

Using Mock DebugSwitch to the debug viewlet and press the gear dropdown. Select the debug environment "Mock Debug". Press the green 'play' button to start debugging.

How to test a method using Mockito?

With Mockito, you create a mock, tell Mockito what to do when specific methods are called on it, and then use the mock instance in your test instead of the real thing. After the test, you can query the mock to see what specific methods were called or check the side effects in the form of changed state.

How does Mockito when thenReturn work?

Mockito when() method It enables stubbing methods. It should be used when we want to mock to return specific values when particular methods are called. In simple terms, "When the XYZ() method is called, then return ABC." It is mostly used when there is some condition to execute.

What is Mockito and how do you use it?

Mockito is a java based mocking framework, used in conjunction with other testing frameworks such as JUnit and TestNG. It internally uses Java Reflection API and allows to create objects of a service. A mock object returns a dummy data and avoids external dependencies.


1 Answers

Mockito 1.9.0 introduced listeners and now bundles a verbose logger:

So basically if you want simple and stupid logs, just do the following:

List mockWithLogger = mock(List.class, withSettings().verboseLogging()); 

See http://docs.mockito.googlecode.com/hg/latest/org/mockito/MockSettings.html#verboseLogging() for more information

Cheers,

like image 150
Brice Avatar answered Oct 04 '22 14:10

Brice