AssertJ - Fluent assertions for java
AssertJ provides a rich and intuitive set of strongly-typed assertions to use for unit testing (either with JUnit or TestNG).
- AssertJ's goals
- Latest News
- Quick start
- Features highlight
- Assertions for your own custom types
- Replacing JUnit assertions by AssertJ Assertions
- Migrating from FEST Assertions
You can ask questions and make suggestions on AssertJ google group.
AssertJ's ambition is to provide a rich and intuitive set of strongly-typed assertions to use for unit testing.
The idea is that, when writing unit tests, we should have at our disposal assertions specific to the type of the objects we are checking. If you're checking the value of a String, you use String-specific assertions. Checking the value of a Map? Use the Map-specific assertions, which make it easy to check on the contents of the map.
AssertJ is composed of several modules:
- A core module (this one) to provide assertions for JDK types (String, Collections, File, Map ...) - see AssertJ Core documentation and javadoc.
- A Guava module to provide assertions for Guava types (Multimap,Optional, ...) - see AssertJ Guava documentation and javadoc.
- A Joda Time module to provide assertions for Joda Time types (DateTime, LocalDateTime) - see AssertJ Joda Time documentation and javadoc.
- A Neo4J module to provide assertions for Neo4J types (Path, Node, Relationship ...) - see AssertJ Neo4J documentation and javadoc.
- A DB module to provide assertions for relational database types (Table, Row, Column ...) - see AssertJ DB documentation and javadoc.
- A Swing module provides a simple and intuitive API for functional testing of Swing user interfaces - see AssertJ Swing documentation and javadoc.
Assertion missing? Please create an issue!
AssertJ's assertions are super easy to write: just type
assertThat followed by the actual value in parentheses and then a dot,
and any Java IDE will show you all the assertions available for the type of the object to verify. No more confusion about the
order of the "expected" and "actual" values. Our assertions are very readable as well: they read very close to plain
English, making it easier for non-technical people to read test code.
A lot of effort have been done to provide intuitive error messages showing as clearly as possible what the problem is.
Note that AssertJ 2.x requires at least Java 7 and AssertJ 3.x requires at least Java 8.
AssertJ core javadoc is published here.
Having assertions for common types like
List is great, but you might want some that are specific to your own types. This is possible with AssertJ because it is easily extensible so it's simple to write assertions for your custom types.
Moreover, to ease your work, we provide assertions generator that can take a set of custom types and create specific assertions. The tools provided are: