Testing beans

In Spring microservices, we create beans that will be used by other components within the application, and as they need to be tested, we can create a JUnit test that uses them. In our example, we have created an interface named CustomerService that has been implemented by the CustomerServiceImpl class, which is annotated with the @Service annotation; this has created a bean in our context that we can test.

First, let's open our CustomerServiceImpl class and select class. We can select the class name and press Shift + Ctrl + T. A new window will appear with the title Choose Test for CustomerServiceImpl with an option to Create New Test. Selecting that option will bring up the Create Test window:

Create Test Window

By default, ...

Get Hands-On Microservices with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.