Randomized testing: Gotta Catch ‘Em All
Wednesday, May 14, 2025
Chance does things well.
If we apply this idea to unit tests or integration tests, we can make our tests much more unpredictable — and as a result, uncover issues that our minds would never have dared to imagine! For example, I recently discovered a bug
in a configuration management library that occurs when the Locale is set to AZ. 🤦🏼♂️
Another, even simpler, example:
int input = generateInteger(Integer.MIN_VALUE, Integer.MAX_VALUE);
int output = Math.abs(input);
This can generate -2147483648… which is quite unexpected for an absolute value! 😉