AssertJ is a Java fluent assertion library for readable, chainable test expectations. In Spring Boot tests, it is supplied alongside JUnit and Mockito and serves as the default assertion style. section 1.1
AssertJ supports practical test-writing needs:
- Express expected values through fluent calls such as isEqualTo. section 1.1
- Produce human-readable failures when assertions are not fulfilled. section 1.1
- Provide a modern alternative to the historical Hamcrest assertion library. section 1.1
A fluent value assertion
After adding one widget, assert the resulting count with: assertThat(widgetCount).isEqualTo(5). section 1.1
Listing 1.1 The spring-boot-starter-webmvc-test dependency in the pom.xml of a typical Boot project
<dependencies>
<!-- ... -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope> #1
</dependency>
</dependencies>
Shows the test-scoped Spring Boot starter dependency pattern used to place testing libraries on the test classpath. section 1.1
