If you are confused with a variety of test libraries in Scala ecosystem like me, then this is article for you.
In this article, I’d like to do a quick tour among Scala frameworks and libs and show capability of each of them on one same example to be able to compare approaches and how final test will look at very high level.
cats-effect- only general-purpose unit testing technologies - but they will be mentioned in the end in a short wrap-up table.
Shapeless coproduct is much better option for error modelling in
Either[L, R] or
EitherT[F, L, R] then regular sealed /sum structures because unlike them:
match is not exhastivewarning, only compilation errors;
Using exception in Scala for error handling often considered as not very good engineering practise, in most of the cases, because it’s not type-safe: when you work with
Try or some effect
F[_] and want handle
Throwable threw from downstream invocations, you never sure that you handling all possible erros because
Throwable is not sealed structure…
This blogpost inspired by StackOverflow answer for question: Compose Futures with Recovery in Scala: is it possible to compose
Future's in a manner if one of them will fail, previous
Future's execution result will be
rolled back via some function.
Future can be generalized to some effect
F[_], so we can say: How we can compose effects
F[_] in a manner if one of them will fail, previous
F[_] execution result will be rolled back via some function. This behaviour similar to what we know as Transaction.
For code solution below
cats-effect version `2.3.1`…