Property Based Testing in Swift

Sebastian Grail, Canva Part of DW18

Automated tests are important to maintaining a robust code base. However, conventional unit tests are often overly specific and only test an arbitrary subset of possible scenarios. Furthermore, they rarely serve as good documentation. Property based tests can help mitigate some of these issues by focusing on describing the relationship between inputs and outputs, and running those tests with a randomly generated set of values. It has been used successfully in functional programming languages for two decades and is now easily achievable in Swift using SwiftCheck, a pure Swift port of one of Haskell’s most prominent testing libraries.

In this workshop, Sebastian gives an introduction to property based testing using the SwiftCheck library. The focus is on familiarising the audience with the concepts of properties, generators and shrinking, and how to apply them to their own code to achieve more meaningful tests and better code coverage. Examples are given in Swift using the SwiftCheck library, but apply to other languages and QuickCheck-style libraries as well.

Slides with speaker notes and sample code will be made available after the talk for further study.