3 ms·
I wonder if they have looked into property based testing in any language which has solid libraries for it. Like the obligatory Haskell examples but also in more
by techdragon 5y ago
I wonder if they have looked into property based testing in any language which has solid libraries for it. Like the obligatory Haskell examples but also in more widespread languages such as Python, which has the phenomenal Hypothesis library https://hypothesis.readthedocs.io/ https://hypothesis.readthedocs.io/
Which allows you to build up the kind of what if scenarios, and also has the primary purpose of allowing you to build the sorts of “simulation space” primitives that they are talking about. “I want to test this code with the first argument as odd integers divisible by 7 and the second argument is random days of the week” and Hypothesis will generate dozens to hundreds (how exhaustive it runs is configurable) of scenarios and run them through the code, which basically does offload the kind of mental simulation debugging the author is talking about.
I’ve driven complex Django installable apps to better than 100% test coverage this way. I had already hit 100% test coverage but the property based testing discovered so many more un-handled behaviour branches that it really elevated the overall code quality to another level. I try to use it for all my Python testing whenever I can. Once you learn (and it’s not super hard to learn how to use it for the basics) it it really isn’t hard to use at all for basic testing.