question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ensure spring-boot can use Mockito public API

See original GitHub issue

Problem

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:closed
  • Created 6 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mockitoguycommented, Oct 3, 2017

Fantastic! I will polish the code / documentation and get the release out soon. Thank you for testing this out and suppling sample project!

1reaction
wilkinsonacommented, Oct 3, 2017

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found