4 ms·
Property-based testing is awesome. I try to write prop-tests by default, with unit tests for explicit 'must test'. The author doesn't mention that Hypothesis d
by staticassertion 7y ago
Property-based testing is awesome. I try to write prop-tests by default, with unit tests for explicit 'must test'.
The author doesn't mention that Hypothesis directly supports combining explicit testcases with your generated testcases. So you can write something like:
'Test list == reverse(reverse(list))`
And ensure that it always tests cases like 'empty list'.(I don't recall the exact syntax and wasn't able to find it with a quick search).
I think this is a nice way of testing because I get to define the testcases I can think of, the edge cases I expect, and also use generated tests where possible.
The downside to using this approach is performance. Especially if you're using this for something that performs IO, this can slow your tests down by 100x (since you run the tests 100s of times more).