Our unit tests most often specify the expected behaviour of a piece of code by defining example scenarios. Each test is a single concrete scenario. When the test suite succeeds, we get the impression that our application works as intended, also for other possible input values. That is, however, not at all guaranteed. It is easy to miss errors due to edge cases that the developer didn’t think about or lack of coverage in the chosen inputs.
In this talk, I will introduce you to property-based testing and how it differs from the more common example-based testing. This testing approach lifts testing to a higher level of abstraction and leaves it to generators to come up with concrete scenarios. The result is a cleaner and more compact test suite that is easier to maintain and better exposes subtle bugs. The hard part of property-based testing lies in defining the suitable properties, and we will look at the best practices to do that properly.
Kotest offers a property test framework that includes generators, shrinkers, and everything else you need to start property-based testing. During my talk, we will see many of its features. We also learn how extension functions and other language features can make our tests even more readable. Don’t you use Kotest? No worries! The property test framework is compatible with JUnit and any other test framework.
About the Speaker Bjorn van der Laan