Hey there! Here we are to the third part of this series (check part 1 and part 2 first if you want to). This time we will look into how we can improve our test assertions using one of two libraries: Kluent and Expekt, that help you to write assertions in a natural language as fluent english sentences.

This time, let’s take a look into a simple User class, with basic info such as name, age, friends and whether or not it can legally drink.

Now let’s take a look into a standard Kotlin test for the logic behind the fullName value:

If you notice, we are using the standard assertEquals to compare the expected value with the actual value. While this works, my opinion is that the tests should always be the most readable possible. This way, if we use any of the fluent assertion libraries, either Kluent or Expekt, we can get a test that looks more elegant.

For instance, if we start of with Kluent we can use the power of Kotlin and infix functions to achieve this assertion:

user.fullName `should equal` "Fábio Carballo"

As you can see, this approach follows the natural english speech, becoming easier to read.