Assertions with AssertJ
Let’s explore the AssertJ library and its set of assertions for Java.
We'll cover the following...
We'll cover the following...
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.
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.
package io.educative.unit;import static org.assertj.core.api.Assertions.*;public class AssertJAssertions {}