liveBook · Manning

AssertJ

As explained in Testing Spring Boot Applications

AssertJ is a Java fluent assertion library that provides readable, chainable test assertions.

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

How Testing Spring Boot Applications covers it

How deep it goes
Demonstrates assertion syntax and failure behavior, but does not detail the broader AssertJ API.
Examples
Uses a widget-count assertion after adding one widget.
What you can do after
Apply it via assertThat and fluent methods to state readable test expectations.
How it connects
Connects AssertJ with JUnit, Hamcrest, Mockito, and Spring Boot testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Testing Spring Boot Applications. The section links point to the parts of the book it draws on.