Ask Your Question
3

What is the Spring Boot implementation of calling a real method using Mockito?

asked 2023-06-15 18:14:38 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-15 18:17:02 +0000

qstack gravatar image

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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2023-06-15 18:14:38 +0000

Seen: 11 times

Last updated: Jun 15 '23