Negative Testing: Relaxing Constraints

Learn the concepts of relaxing constraints in generators to find bugs that were previously not found.

Relaxing constraints

While metrics are always a good thing to keep an eye on, another very interesting way to improve our negative tests and explore the program’s problem space is to play with constraints and relax them with existing generators.

The way we relax constraints is usually through simple code modifications. We’ll modify a bunch of generators, making them less strict so they trigger some unexpected cases. Then we find out why that happened, revert the change, and then either add a unit test or a property test to validate the bug before fixing it.

Then we can rinse and repeat, gradually weeding out more and more bugs from our code.

Get hands-on with 1200+ tech skills courses.