Ensure spring-boot can use Mockito public API
See original GitHub issueProblem
Mockito framework integrators need robust public APIs from us. This way, they ship great Mockito integrations to their customers. We want to avoid the situation where framework integrators have to use Mockito internal APIs. This leads to overhead, relying on stale versions of Mockito, class conflicts in runtime.
spring-boot currently uses some internal API from Mockito. See https://github.com/spring-projects/spring-boot/issues/10352 for the problem statement, solution options and chosen design.
Solution
As discussed in spring-boot ticket, here’s the API we would like to prototype:
- New “VerificationStartedListener”
- The instance of listener can be passed on mock creation
- Listener is notified when ‘Mockito.verify’ is invoked but before the verification is triggered
- It is possible to replace the mock object that is being verified (key feature needed by spring-boot)
Example usage
mock(Foo.class, withSettings().verificationStartedListeners(new VerificationStartedListener() {
public void onVerifyStarted(VerificationStartedEvent event) {
event.getMock();
event.setMock(arbitrayObject);
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Testing Spring Boot RESTful APIs using MockMvc/Mockito ...
This project serves as a Spring Boot testing demo for a simple web app. The post covers testing the same web app API...
Read more >Mocking a RestTemplate in Spring - Baeldung
A simple guide to mocking when using Spring's RestTemplate. ... We can use Mockito to mock the RestTemplate altogether.
Read more >Unit Testing in Spring Boot Project using Mockito and Junit
Mockito is an open-source testing framework used for unit testing of Java applications. · Step 1: Refer to this article How to Create...
Read more >Spring Boot REST Integration Test with Mockito Java JUnit ...
In this tutorial I show you how to Mock your Spring controller service classes with the new Spring Boot 1.4+ Mockito annotations.
Read more >Spring Boot + JUnit 5 + Mockito Tutorial - YouTube
Welcome to Spring boot + Junit Tutorial Introduction to Software Testing in this video we will create a basic Spring application and use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fantastic! I will polish the code / documentation and get the release out soon. Thank you for testing this out and suppling sample project!
@szczepiq This looks great. I’ve built the
mockito-spring-boot
branch and prototyped the updates required for Spring Boot to use it: https://github.com/wilkinsona/spring-boot/tree/gh-10352. All our tests pass and, as you can hopefully see, Boot’s code is now significantly simpler. Thanks very much.