Unit testing

The smallest scoped tests we can write are referred to as unit tests. In fact, people have been writing tiny tests for years. A common paradigm is to try and test just one class in a given unit test.

To get going, let's test the smallest unit of code we have: our Lombok-enabled Image domain object.

As a reminder, here is what that code looks like:

    @Data 
    @Document 
    public class Image { 
        @Id final private String id; 
        final private String name; 
    } 

This tiny little POJO is flagged with Spring Data MongoDB annotations as well as Lombok's @Data annotation providing getters and setters.

A unit test shouldn't be too hard. We can start by creating ImageTests.java in /src/test/java, and in the same package as the original class (com.greglturnquist.learningspringboot ...

Get Learning Spring Boot 2.0 - Second Edition 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.