Day-to-Day Property Based Testing in Scala
We all like the idea of building high quality and robust code, covering all the possible and impossible edge cases. Maybe this is why many of us are getting hooked on the Property-based testing approach or at least we are not opposed to try it out.
It gives us an ability to run a single test case hundreds of times on a large range of data, covering edge cases we’ve never thought we had in the first place.
However, if you are like me and your day-to-day job is to create an API and save data into a database or maybe even send it over to another API, you also probably struggled to come up with a good application of this practice. It is easy and “very useful” to test that a reverse of a collection is still working. But, when it comes to if-else conditions, we find it hard to come up with the right property to test.
In this talk I would like to focus on a practical application of this concept, presenting some examples in ScalaCheck. I will start with a summary of what Property-based testing (PBT) framework equips you with and what should you expect from it. There will be basic examples demonstrating the power of PBT. But mostly, I will cover existing patterns and tips you can take to your normal life projects and use them to leverage this PBT tool.
About Svetlana Marina Svetlana is a Software Engineer at ThoughtWorks. She likes delivering software into production and making this a joyful process. She's is a polyglot and during her career she had a chance to work with quite a set of different languages. The most impactful of them for her was Scala, which introduced her to the world of functional programming. Since then, she always tried to adopt FP concepts on her projects, even if they were in the mainstream non-fp languages.