Testing first is a great deal for us. We have built upon this principle everything we have, and it definitely works well for us. However, not every testing framework was designed with easiness in mind and sometimes we have to build upon them to get a more refined product that just works better for our special needs for simplicity.

ScalaTest is quite impressive and it has very interesting capabilities. The one we like the most is that we can extend it by adding our own matchers which ultimately gives us the level of abstractions we are looking for.

Let’s start by supposing we want to test a function of the fallowing signature.

A very simplistic test for it could be

As we can see, this is a very simplistic test, but now let’s find a user given an user id.

We could write a test for it as follow.

Wait what? do we actually have to unwrap the monad Option ? Well, the other option is the fallowing.

This is kind of the same, the different is that we are now wrapping User into Some which is basically the same.

What we actually want to write is something like the following.

As we can see, in here our intention is way more clear (This code won’t compile, yet)