Alex is a Software Engineer working on Android development tools, especially Android Studio, at Google. His interests include Java, API design, OOP, IDEs and testing. Alex spends some of his spare time working on Open Source, blogging, writing technical articles, and speaking at international conferences. The opinions expressed here represent his own and not those of his employer. Alex is a DZone MVB and is not an employee of DZone and has posted 49 posts at DZone. You can read more from them at their website. View Full User Profile

FEST-Assert 1.4: Fluent Interface for Assertions

03.08.2011
| 2649 views |
  • submit to reddit

We are proud to announce that FEST-Assert 1.4 is out!

FEST-Assert is an “assertThat” library that provides a fluent interface for writing assertions. Its main goal is to improve test code readability and make maintenance of tests easier.

Example:

int removed = employees.removeFired();
assertThat(removed).isZero();
 
List newEmployees = employees.hired(TODAY);
assertThat(newEmployees).hasSize(6)
.contains(frodo, sam);
 
String[] newHires = employees.newHiresNames();
assertThat(newHires).containsOnly("Gandalf", "Arwen", "Gimli");
 
assertThat(yoda).isInstanceOf(Jedi.class)
.isEqualTo(foundJedi)
.isNotEqualTo(foundSith);

One of the biggest changes in this release is the implementation of Ansgar’s "Self Types." By using this brilliant technique we ended up with a smaller, cleaner code base that is easier to maintain.

Here are some numbers, comparing this release with the previous one:

Release Lines of code Tests Code coverage
1.3 3,132 3,707 98.7%
1.4 2,051 1,849 100%

Please note that 1.4 has more features than 1.3 and yet the code base is 35% smaller!

Release notes

Bug
  • [FEST-378] - Newly added assertThat(Iterable<?> actual) eagerly calls iterator() and can throw an NPE
  • [FEST-402] - onProperty is unable to access properties from Object class
  • [FEST-414] - Impossible to use Fest Assert 1.3 with Ivy
  • [FEST-415] - IteratorAssert should delay Iterator comsumption as much as possible
  • [FEST-416] - NPE in MapAssert due to FEST-329
Improvement
  • [FEST-105] - Add isEither, or isOneOf
  • [FEST-413] - Implement Ansgar's Self Types
  • [FEST-423] - User-friendly date and calendar formatting
New Feature
  • [FEST-111] - Add support for regular expression matching to StringAssert
  • [FEST-381] - collection onProperty() assert might give nicer exceptions
  • [FEST-400] - Add generic assertions isIn / isNotIn

You can download the latest release here (file fest-assert-1.4.zip.) FEST-Assert requires Java SE 5.0 or later.

Here are some useful links:

Feedback is always appreciated :)

0
Average: 5 (1 vote)
Published at DZone with permission of Alex Ruiz, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)