How not to implement a failing test


One of the first things I change in ReSharper, along with one of my biggest pet peeves is a failing test that fails because of something like this:

public class CombinedStreetAddressResolver 
    : NullSafeValueResolver<Address, string>
{
    protected override string ResolveCore(Address model)
    {
        throw new NotImplementedException();
    }
}

In the Red-Green-Refactor progression, the Red of a failing test should come from an assertion failure not a “my code is stupid” failure.  The Red part is intended to triangulate and calibrate your test, to make sure that your test can fail correctly.  A NotImplementedException won’t cause a meaningful failure, and only serves the purpose of getting your code to compile.

Throwing exceptions means your assertions never get executed in RGR until you attempt to make a passing test, in which case you still haven’t proven your test to be correct.  If you don’t know that your test is correct, you have two points of failure: your test, and code under test.

That’s why I’ve set ReSharper to return default values instead of throw exceptions.  I want meaningful failures from a valid test, otherwise I’m better off skipping the Red step altogether.

More missing LINQ operators