I have a class that is responsible for performing conversions from/to twenty-something types. Let's call this class ConvertUtils
.
For C# programmers out there - this class expands .Net's Convert
class.
It looks something like this:
public static class ConvertUtils {
public static object ChangeType(object obj, Type newType) {
if (conversionSupportedByFramework)
return Convert.ChangeType(obj, newType);
else
ConvertSpecialCases(obj, newType);
}
}
How would you go about testing it? I'm assuming we do need to black-box test this code.
The two ways we thought about, are:
- Writing 400+ unit tests - cover all to/from combinations that we can think of.
- Write tests only for the new conversions - the ones not supported by the
Convert
class - actually testing only theConvertSpecialCases()
function [which isn't our goal, as stated above]
The con of the first possibility is to have too many tests - which prolongs the build time, involves maintaining more code, etc.
The con of the second possibility is to not fully check the responsibility of the class -
what if a certain if
statement decides to implement (wrong) custom logic, instead of letting Convert
do it's job? e.g. just before if (conversionSupportedByFramework)
someone decides to call some custom logic?
What do you think about this issue?