JUnit 5 + AssertJ examples

In this article, we will show you how to write test assertions with AssertJ. P.S Tested with JUnit 5.5.2 and AssertJ 3.14.0 pom.xml <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.5.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>3.14.0</version> <scope>test</scope> </dependency> 1. JUnit 5 assertions to AssertJ It’s easy to convert JUnit 5 assertions to AssetJ, see the following syntax: JUnit …

Read more

Hamcrest – How to assertThat check null value?

Try to check null value with the Hamcrest assertThat assertion, but no idea how? @Test public void testApp() { //ambiguous method call? assertThat(null, is(null)); } 1. Solution 1.1 To check null value, try is(nullValue), remember static import org.hamcrest.CoreMatchers.* //hello static import, nullValue here import static org.hamcrest.CoreMatchers.*; import org.junit.Test; //… @Test public void testApp() { //true, …

Read more