AssertJ assertions generator

The Assertion Generator is able to create assertions specific to your own classes, it comes with a simple command line tool and a maven plugin.

Having the possibility to create assertions specific to your own classes is important because it makes your test assertions reflect the domain model. It's a way to use Domain Driven Design ubiquitous language in your tests. Custom assertions can be seen as a DSL of domain assertions.

Let's say that you have a Player class with name, team and teamMates properties, the generator is able to create a PlayerAssert assertions class with hasName and hasTeam assertions. Use it to write code like :

assertThat(mj).hasName("Michael Jordan")
              .hasTeam("Chicago Bulls")
              .hasTeamMates("Scottie Pippen", "Tony Kukoc");

The generator will also create entry point classes like Assertions, BddAssertions and SoftAssertions/JUnitSoftAssertions to ease accessing each generated *Assert classes. In the case where PlayerAssert and GameAssert have been generated, the generated Assertions class will look like:

public class Assertions {

   * Creates a new instance of <code>{@link GameAssert}</code>.
   * @param actual the actual value.
   * @return the created assertion object.
  public static GameAssert assertThat(Game actual) {
    return new GameAssert(actual);

   * Creates a new instance of <code>{@link PlayerAssert}</code>.
   * @param actual the actual value.
   * @return the created assertion object.
  public static PlayerAssert assertThat(Player actual) {
    return new PlayerAssert(actual);

   * Creates a new <code>{@link Assertions}</code>.
  protected Assertions() {
    // empty

This quickstart guide is for non maven users, if you are a maven user, you should use the assertions generator maven plugin.

Get the AssertJ Assertions Generator archive (either for unix or windows) and extract it, its structure is :

  |-- lib/
  |-- templates/
  |-- generate-assertions script (.bat or .sh)

First, put in lib/ the jars containing the classes you want to generate assertions for, then run the script with either the classes or the packages containing the classes you want to generate assertions for.

Example : generating assertions for TolkienCharacter class :

Example : generating assertions for all classes in :

Your assertions classes have been generated ! You can find them in the current directory.

Tip :

You can change what is generated by modifying the templates used for assertions creation (have a look at templates directory)

Release date : 2015-04-11

Huge thanks to Jeremy Krieg for his contributions to this release.

  • Generate hasOnly and doesNotHave assertions for array/iterable properties.
  • Better error messages.
  • Sanitise property names when they clash with Java keywords. (Fr Jeremy Krieg)
  • Skip generation of field assertion if it would cause a name clash with a property assertion. (Fr Jeremy Krieg)
  • Handle other boolean predicate forms than is like was, can, will, shouldBe. (Fr Jeremy Krieg)
  • Generated iterable/array assertions did not to honour the description set with as() method when given iterable/array was null.

Release date : 2014-11-02

  • Generate JUnitSoftAssertions.
  • Fix potential import clash by using fully qualified class names (except for AssertJ classes).
  • Fix class cast exception when an overriden getter returns a generic type.

Release date : 2014-08-31

  • Fixes bad generated code in hasNoXXX assertion for iterable property.
  • Fixes bad generated code in contains assertion for iterable property with upper bound wildcard (? extends).
  • Fix to generate assertion for classes having '$' character in class name.
  • Fix fenerated assertion for public boolean field.
  • Use fully qualified name class instead of import in Assertions entry point classes.

Release date : 2014-08-17

  • Correctly resolve generic return types.
  • Use Guava ClassPath instead of org.reflections.

Release date : 2014-08-03

Big thanks to Fr Jeremy Krieg for his work on this release.

  • Generate assertions using offset for double and float types.
  • Allow to generate assertion classes that don't hide subclasses assertions after using an assertion from a super class. (Fr Jeremy Krieg)
  • Generate assertions for public fields.
  • Prepend enclosing class name to inner class assertion name to avoid clash when several inner classes have the same name.
  • Don't generate classes with unused import. (Fr Jeremy Krieg)
  • Generated javadoc improvements. (Fr Jeremy Krieg)
  • Allow to specify where to generate Assertions entry point classes. (floppywaste)
  • Generate a BDD style entry point class BddAssertions replacing assertThat methods by then.
  • Generate a SoftAssertions entry point class to collect all assertion errors instead of stopping at the first one.

Release date : 2013-12-08

  • To ease using generated assertions, generate an entry point class Assertions providing assertThat methods giving access to each generated *Assert classes.
  • Don't generate hasDeclaringClass assertion for Enum.
  • In generated method assertions, rename errorMessage local variable to assertjErrorMessage to avoid collision when object under test has an errorMessage property. (William Delanoue)

Release date : 2013-09-15

Big thanks to Fabien Duminy, he has done most of the work of this release !

  • Generated assertions use null safe equals for non primtive types.
  • Add exceptions to assertion method signature if underlying getter of class to assert throws some. (Fabien Duminy)
  • Generate assertions for nested/inner classes. (Fabien Duminy)
  • Fix error message displaying unrelevant property value when getter of class to assert doesn't return the same value on successive calls. (Fabien Duminy)

Release date : 2013-03-26

It's the first release after Fest fork, generated assertions are cleaner.

If you have any questions, please use AssertJ google group.

AssertJ assertions generator is hosted on github :

Please report bugs or missing features in AssertJ assertions generator issue tracker.

Thanks for your interest ! Please check our contributor's guidelines.

Special thanks to AssertJ assertions generator contributors:

  • Fabien Duminy
  • William Delanoue
  • floppywaste
  • Fr Jeremy Krieg