AssertJ
AssertJ is a Java assertion library that provides a fluent, chainable API for writing expressive, readable assertions in unit tests.
Definition
AssertJ is a Java assertion library that provides a fluent, chainable API for writing expressive, readable assertions in unit tests.
Overview
AssertJ lets developers write assertions such as assertThat(list).hasSize(3).contains(x) instead of more verbose, less descriptive calls, with rich, type-specific assertions for collections, exceptions, dates, and custom domain objects. It's typically used alongside test runners like JUnit or TestNG and build tools such as Gradle or Apache Maven, often in Java projects also built with Spring Boot. AssertJ improves test failure messages compared to plain JUnit assertions, in much the same spirit that Jest's expect API improved assertion readability in JavaScript testing.
Key Features
- Fluent, chainable assertion API (assertThat(...).is...())
- Rich, type-specific assertions for collections, maps, exceptions, and dates
- Descriptive failure messages that speed up debugging
- Soft assertions that collect multiple failures before reporting
- Extensible with custom assertion classes for domain objects