Once upon a time, I saw the following regular expression in a production code. I will write it in C#, but the language or platform doesn't mean much.
Let's say now that you have one unit test to make sure that your "boundary case" is accepted.
public static bool IsValidIp(string ipAddress)
{
return new Regex(@"^([0-2]?[0-5]?[0-5]\.){3}[0-2]?[0-5]?[0-5]$").IsMatch(ipAddress);
}
Now you are happy, get the code checked in, and brag that you have 100% code coverage for that IsValidIp method. And so what? A simple "192.168.1.1" IP address is not considered a valid address. Completely buggy code, but 100% code coverage.
Assert.IsTrue(IsValidIp("255.255.255.255"));
That is why managers that really understand what is being developed and have the chance to spend time looking at the code can make a total difference in the final product's quality.
Note: on the case above, it's amazing that the developer did not Google'd for the right regular expression for Ip validation, did not write data-driven unit tests to make sure different Ips are being written, and that code reviewers did not review it properly.
0 comments:
Post a Comment