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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-15 18:14:38 +0000
Seen: 11 times
Last updated: Jun 15 '23
Can the Bridge Pattern separate the implementation from the abstraction?
What is the implementation of the Bubble Sort Algorithm using C programming language?
What is the implementation of Jetpack Compose's nested LazyColumn/LazyRow?
What is the process of creating instances of interfaces called?
What is the process for adding mock services to WebApplicationFactory in C# using injection?
Why is Pytest monkeypatch not functioning on a function that has been imported?
What is the method for altering the color of the input text in a TextFormField in Flutter?