Posts

Showing posts from October, 2026

Static Data Trap. All Tests Passed. But Why is the Output Wrong?

Code coverage is not enough Code coverage is one of those metrics which can easily give you a false sense of security. In real life, code achieving 100% code coverage is often not possible, but that is the least of the problems with using code coverage as a metric of how well-tested some code is. There are some parts of the code and logic that code coverage tools simply cannot cover. Even if you have achieved 100% code coverage for some code, you might still have serious flaws in that code. Every branch is taken, every line is green, all your tests are passing. There is nothing left to do. Right? Wrong? Probably one of the simplest examples that can show this problem is converting a decimal integer number to some other base: const BaseChars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; function IntToBase(Value, Base: UInt32): string; begin Result := ''; while Value > 0 do begin Result := (BaseChars[1 + (Value mod Base)]) + Result; Value := Va...