Almost a year ago I wrote a series of blog posts on how to use property-based tests in C#.
- Part 1 – Introduction
- Part 2 – An example
- Part 3 – Finding edge cases
- Part 4 – Writing your own generators
- Part 5 – Locking input
In this series I used FsChttps://fscheck.github.io/FsCheck/heck as the library of my choice. Although originally created for F#, it also works for C# as I have demonstrated.
However as it was originally created for F#, it sometimes feels strange when using FsCheck in C#. If you prefer a more idiomatic alternative, you can have a look at CsCheck, also inspired by QuickCheck but specifically created for C#.
CsCheck offers no specific integration but can be used with any testing framework(XUnit, NUnit, MSTest, …).
Here is a small example:
CsCheck does it really well in the shrinking challenge and offers support for multiple types of tests including concurrency testing.
This is a feature I really like as concurrency related issues are really hard to find and debug. When writing this type of tests, you specify a set of operations that will be executed concurrently and then be compared with linearized execution.
Here is an example: