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.
Asked: 2023-06-15 18:14:38 +0000
Seen: 11 times
Last updated: Jun 15 '23