Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To call a real method using Mockito in Spring Boot, you can use the following code:

MyService myService = Mockito.spy(new MyServiceImpl());
Mockito.doCallRealMethod().when(myService).myMethod();

In this example, MyService is the interface for a service, and MyServiceImpl is the implementation. We first create a spy object for MyServiceImpl. Then, we tell Mockito to call the real implementation of myMethod by using doCallRealMethod(). Finally, we can use the myService object to call the real myMethod implementation.