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
), as follows:
public class ImageTests { @Test public void imagesManagedByLombokShouldWork() { Image image = new Image("id", "file-name.jpg"); assertThat(image...