O'Reilly logo

Spring Boot Cookbook by Alex Antonov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating tests using Mockito to mock DB

Now that we are done with setting up the fixtures to use during the set up and population of our database when it is used for testing purposes, let's examine how we can use the power of Mockito so that we don't need to rely on the database at all. We will learn how to elegantly mock the Repository instance objects using the Mockito framework and some annotation cleverness.

We will create a special Spring Boot configuration class where we will define and replace the Spring Beans that are necessary for testing purposes. We will use annotations to tell Spring Boot when to add the testing configuration and when to exclude it. In the configuration class, we will use Mockito to create some mock objects with preconfigured ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required