The Assertion Generator is able to create assertions specific to your own classes, it comes with :
- a CLI tool
- a maven plugin
- an eclipse plugin (planned for April).
- an idea plugin who is a fork of the JUnit Generator v2 plugin
Let's say that you have a Player
class with name
and team
properties, the generator is able to create a PlayerAssert
assertions class with hasName
and hasTeam
assertions, to write code like :
assertThat(mvp).hasName("Lebron James").hasTeam("Miami Heat");
2013-03-26 : 1.0.0 release : the first release after Fest fork, generated assertions are cleaner.
You should use the provided maven plugin.
We have developed an Eclipse plugin that allows you to generate assertions for a specific class (one at time only).
Please check AssertJ eclipse plugin documentation.
Get the AssertJ Assertions Generator 1.0.0 archive for unix or windows and extract it.
The archive structure is :
assertion-generator/
|-- lib/
|-- templates/
|-- generate-assertions script (.bat or .sh)
-
Put in
lib/
directory the jars containing the classes you want to generate assertions for . -
Launch the scripts with either the classes or the packages containing the classes you want to generate assertions for.
Generate assertions for TolkienCharacter
class :
generate-assertions.sh org.assertj.examples.data.TolkienCharacter
Generate assertions for all classes in org.assertj.examples.data
:
generate-assertions.sh org.assertj.examples.data
- your assertions classes have been generated, go 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)