Imagine a psedo-code class like this which does name comparisons:
public class NameComparer
{
public bool DoNamesMatch(Name name1, Name name2)
{
if(WholeNameMatch(name1, name2))
{
return true;
}
return ProcessorIntensiveFuzzyMatcher(name1.Forename, name2.Forename)
&& ProcessorIntensiveFuzzyMatcher(name1.Surname, name2.Surname)
}
private bool WholeNameMatch(Name name1, Name name2)
{
return (name1.Forename == name2.Forename)
&& (name1.Surname == name2.Surname);
}
private bool ProcessorIntensiveFuzzyMatcher(string string1, string string2)
{
// complex fuzzy matching
}
}
Best practice suggests that this class only ought to have one public method, and that we ought to unit test the private methods in this class through that public method.
While I can write various tests that ensure WholeNameMatch
and ProcessorIntensiveFuzzyMatcher
both do what they're supposed to do, the order of operation is important here. If a developer mistakenly moves one above the other, the program is going to take a massive performance hit.
Is it desirable - and possible - to test this order of operations via the exposed public method?
public
method must execute in x time) that can be tested with another unit test, given some assumptions about the hardware you're running the tests on.