Assertions with AssertJ
Let’s explore the AssertJ library and its set of assertions for Java.
AssertJ
We’ve used the Assertions
class of the JUnit5 framework in all our unit and integration tests for comparing expected and actual results. However, the AssertJ library offers fluent assertion APIs with better code readability and error messages.
Setup
Let’s add the core AssertJ dependency in the build.gradle
file of our todo
application.
Press + to interact
dependencies {testImplementation "org.assertj:assertj-core:3.22.0"}
The AssertJAssertions
class
We’ll create the AssertJAssertions
class to make a few assertions by using the AssertJ’s Assertions
class.
Press + to interact
package io.educative.unit;import static org.assertj.core.api.Assertions.*;public class AssertJAssertions {}