Property-based testing: from examples to properties with Kotlin and Kotest | Bjorn van der Laan

with

Details

Our unit tests most often specify the expected behavior 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.

Job board

Go for that next step in your career! Learn more about Kotlin related job openings at awesome companies.

Community Sponsors

Gold sponsors

Silver sponsors

Digital Sponsors