← Back to context

Comment by reverius42

17 hours ago

I think what they meant is, "won't Hypothesis sometimes fail to generate input with an apostrophe, thus giving you false confidence that your code can handle apostrophes?"

I think the answer to this is, in practice, it will not fail to generate such input. My understanding is that it's pretty good at mutating input to cover a large amount of surface area with as few as possible examples.

Hypothesis is pretty good, but it's not magic. There's only so many corner cases it can cover in the 200 (or so) cases per tests it's running by default.

But by default you also start with a new random seed every time you run the tests, so you can build up more confidence over the older tests and older code, even if you haven't done anything specifically to address this problem.

Also, even with Hypothesis you can and should still write specific tests or even just specific generators to cover specific classes of corners cases you are worried about in more detail.

  • > But by default you also start with a new random seed every time you run the tests, so you can build up more confidence over the older tests and older code

    Is it common practice to use the same seed and run a ton of tests until you're satisfied it tested it thoroughly?

    Because I think I would prefer that. With non-deterministic tests I would always wonder if it's going to fail randomly after the code is already in production.

    • You should save the seeds so you can reproduce the issue. But you should let the seed float so that you test as many cases as possible over time.

    • the more the test runs the less likely it is there is an uncovered case left. So your confidence grows. Remember too anything found before release is something a customer won't find.

    • Saving the seed in the build artifacts/logs has saved a lot of time for me even with tools like faker.