Fest Asserts

September 20, 2013
Testing Fest Unit Testing

Just a quick post about the awesomeness of Fest Asserts. Fest asserts is a fluent interface for Unit testing assertions.

I’ve always traditionally used Hamcrest Matchers with my JUnit tests. After using Fest asserts (https://github.com/alexruiz/fest-assert-2.x) with Play, I’ve been converted.

 So let me give you an example.

With Hamcrest matchers, a simple string equality assertion is performed as follows:


assertThat(client.getUser(), is(“John”));

With Fest, it is performed like this:


assertThat(client.getUser()).isEqualTo(“John”);

The change between the two is very subtle, however the impact is great.

 Since Fest doesn’t rely on static importing, it is much easier to ‘auto-complete’ Fest methods than it is to ‘auto-complete’ the statically imported Hamcrest matcher methods. Basically IDEs are much better at autocompleting methods belonging to Objects/Classes than methods that require static imports.

Also another consequence of not relying on static importing, is that you’ll potentially run into fewer collisions with other static imports with the same name. Especially if you statically imported with ‘*‘, the chance of colliding with another method with the same name is high.

 For more information, see http://fest.easytesting.org/. There’s also http://www.fluentlenium.org/ a fluent interface for selenium and assertj which is a fork of fest.