Test the Right Thing

I was helping a customer recently to improve the way they do testing and I looked at one of their tests as follows:

[TestMethod]
public void FeedFileProcessorResolvesLoadDirectoryViaFeedType()
{
  MockRepository mocks = new MockRepository();
  using (MockServices services = new MockServices(mocks))
  {
    FeedType feedType = MockServices.CreateStubFeedType(1001, null, null, @"z:\PickUpDirectory");
    Expect.Call(services.FeedTypeProvider.GetByFeedTypeID(feedType.FeedTypeID))
      .Return(feedType);
    mocks.ReplayAll();

    MockFeedFileProcessor.DefaultFeedTypeId = 1001;
    FeedFileProcessor processor = new MockFeedFileProcessor();
    string loadFilesFrom = processor.DirectoryToLoadFilesFrom.FullName;

    mocks.VerifyAll();

    Assert.AreEqual(@"z:\PickUpDirectory", loadFilesFrom);
  }
}

On first glance it seems reasonable.  The test is named so that it describes what it does and seems to work through checking that the object behaves as it should. Sure the Rhino Mocks syntax could be updated to use AAA syntax, and the using section doesn't really indicate what's going on under the hood there but apart from that it doesn’t look too bad.

Look a little closer though and check out the class under test and you may see a small problem.  That’s right, the only class being tested here is the mock itself.  Not something that you really want to do.

By not actually testing a class from our production code we’ve made the test have zero value for the system itself.

 

Reader Comments

Post a Comment



Welcome

As you might have guessed, this is a tech blog. I normally write about development and things that can help us do it better, specifically in the .NET space, and occasionally i'll throw in a post about whatever happens to be in my head at the time. Enjoy your visit!
And in case you were wondering, I'm a Principal Consultant for Readify, I run the Sydney Alt.Net group and I play a bit of LOTRO in my spare time (feel free to look me up)


 

My Open Source Projects

Labels

Blog Archive