Hi Guys,
It was possible to make your own assertions but it was not that straightforward so we decided to provide tools to generate Fest assertions.
Use case : Let's say that you have a Player class with name and team attributes, 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");Note that the tools is able to generate all the assertions for classes in a specified package.
There are several ways to launch the assertions Generator :
- a
Maven plugin- a
command line tool (unix shell or windows .bat)
- soon available an
eclipse plugin (in few weeks - stay tuned)
The Maven plugin is the easiest way to generate assertions for the time being, so I'm gonna describe how to use it (it only lacks the possibility to change the assertions template ... for the time being).
To use the maven plugin, you need to :
- add FEST Assertions as a dependency in pom.xml e.g (version 2.x is required)
- specify the packages containing the classes you want to generate custom assertions for (typically set the the package of Player class if you want Player assertions)
- optionally, set the directory where assertions files will be generated (default to
target/generated-test-sources/assertions)
- call
mvn generate-test-sources or simply mvn testFest assert dependency :
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert-core</artifactId>
<version>2.0M8</version>
<scope>test</scope>
</dependency>
To generate custom assertions, add the following plugin to your
pom.xml build/plugins section :
<plugin>
<groupId>org.easytesting</groupId>
<artifactId>maven-fest-assertion-generator-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<goals>
<goal>generate-assertions</goal>
</goals>
</execution>
</executions>
<configuration>
<packages>
<param>your.first.package</param>
<param>your.second.package</param>
...
</packages>
</configuration>
</plugin>
packages configuration element is required in order to generate assertions for classes located in the specified packages.
You can also specify non-standard destination directory for assertion files using
targetDir configuration element e.g.
<configuration>
<packages>
<param>your.first.package</param>
<param>your.second.package</param>
...
</packages>
<targetDir>YOUR_NON_STANDARD_DIR</targetDir>
</configuration>Have good assertions and give us some feedback to improve the tools !
Cheers,
Joel