The Assertion Generator is able to create assertions specific to your own classes, it comes with :
- a CLI tool (this project)
- a maven plugin
- an eclipse plugin (planned later).
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-09-15 : 1.1.0 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)
Big thanks to Fabien Duminy that has done most of the work of this release !
2013-03-26 : 1.0.0 release : the first release after Fest fork, generated assertions are cleaner.
You should use the provided maven plugin.
Work (not so much) in progress ...
We are developing 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)