5 ms·
I use property-based testing a lot: - We write our unit tests as functions, accepting some arguments - Our assertions should hold for all possible values of t
by chriswarbo 4y ago
I use property-based testing a lot:
- We write our unit tests as functions, accepting some arguments
- Our assertions should hold for all possible values of those arguments (this works better with a rich type system!)
- The test framework generates a bunch of random values, to check if our test functions ever fail
This on its own is a great way to find edge-cases, and expose hidden assumptions.
One of the most hacky things I've done with it is to regression-test interactions between dynamic binding and futures. My test suite defined a small language, containing strings, concatenation, dynamic variables and futures (deferring and awaiting). I wrote a straightforward, single-threaded implementation which just computed deferred values immediately; and I wrote a concurrent implementation using actual dynamic binding and futures. My property-tests would generate random expressions in this language, and check that both interpreters give the same result.