Property-Based Testing - Examples of Properties from Business Applications
I got excited about property-based testing after hearing John Hughes talk at Functional Conf 2016. I tried it that year with QuickCheck, but failed miserably (it almost derailed the entire project delivery). I cribbed about it in my talk at Functional Conf 2017. In 2018, Srihari's talk got me excited again. This time, I tried with Hedgehog, and got it to work!
This talk is about this journey and its learnings. We'll talk about how Hedgehog was used to test [1]:
- A Postgres backed task/job queue
- A small Wai/Servant based webapp
And no, we will not talk about the most common (and completely useless) example of reversing a list!
[1] Both of these are part of an open-sourced task/job queue library.
Outline/Structure of the Case Study
- Understanding property-based testing of pure code through real-world examples
- Problems faced while testing stateful code (most commonly where state is stored in a DB)
- Approaches used by various libraries for testing stateful code
- Walk-through of how property tests were used to ensure correctness of a Postgres-backed job/task queue
- Walk-through of how property tests were used to test a small DB-backed webapp
Learning Outcome
How to use property-testing effectively in typical web applications
Target Audience
Tech Leaders and Engineers interested in TDD and Testing at large
Links
- "Refresh-driven" development in Haskell & Elm (FnConf 2018) - https://www.youtube.com/watch?v=CUoisP60vGI&list=PL9Z-JgiTsOYTtq49muYrjsERqTZcahEZL&index=16&t=0s
- Real-wold Haskell: The Good, Bad, & Ugly (FnConf 2017) - https://www.youtube.com/watch?v=7NB8tMa8sUk
- Why building webapp is Haskell is harder than it ought to be - https://medium.com/@saurabhnanda/why-building-web-apps-in-haskell-is-harder-than-it-ought-to-be-c9b13de0be4f
- Benchmarks: GHCJS (Reflex, Miso) & Purescript (Pux, Thermite, Halogen) - https://medium.com/@saurabhnanda/benchmarks-fp-languages-libraries-for-front-end-development-a11af0542f7e