Property-Based Testing - Lucy Mair - NDC London 2023 - 2023
Details
Title : Property-Based Testing - Lucy Mair - NDC London 2023 Author(s): NDC Conferences Link(s) : https://www.youtube.com/watch?v=8xSoeMJhe98
Rough Notes
Property-Based Testing depends on knowing some properties that must be satisfied by some procedure. E.g. if we have a function ReverseList
that reverses a list, we know that:
- Reversing a reversed list returns the original list.
- For non-empty lists, its first item will be the last item in the reversed list.
- For lists that a palindromes, reversing that list returns the same original list.
Example case when there is randomness : If we have a function RandomSample
that selects a subset of a list without replacement, we can test if concatenating the output of that function with the list that is left afterwards is the same as the original list.
Another use case is when the solution is easy to verify but hard to prove - e.g. for a sorting algorithm, one can write a test to generate consecutive pairs of a sorted list and check if they satisfy the sorting relation.
Another (more common) use case when replacing a legacy function.
Another use case is forward and reverse functions, like Serialize
and DeSerialize
functions.
Another use case is to check if a part of the range of possible outputs is valid, e.g. an estimator for a covariance matrix returns a positive-definite result.