Showdown: Testing Private Methods vs Public Methods

   Submit to Reddit      

The concept of testing private methods has been debated by many people, and up until now I have been happy to sit on the fence.

However, recently I have been looking at simplifying and optimising automated testing code. As part of that process, I created a small sample application with one public service operation method that calls a number of private methods.

In order to answer the question about whether there are worthwhile advantages to testing private methods, I decided to do a shoot-out of automated testing code. Here was the line up:

  • All the test code required to thoroughly test the sample application by testing both private and public methods; and
  • All the test code required to thoroughly test the sample application by testing just the public methods.

The result was conclusive: in order to thoroughly test the sample application, less test cases were required and significantly less automated testing code was required when just explicitly testing the public methods (and implicitly testing the logic in private methods).

Here is a summary of my findings.

  • Less test cases were required because test cases for the logic contained within the private methods overlapped with test cases that were still required in order to thoroughly test the public methods;
  • The private methods were still thoroughly tested implicitly through the test cases for the public methods; and
  • The resulting test code was less brittle so developers can more freely refactor the application code without easily breaking the test code.

Don't believe me? Perform a similar exercise for yourself!

TeamReview 2010 Installation Problem

   Submit to Reddit      

The other day, a work colleague asked for my assistance regarding a problem installing TeamReview 1.1.2 (for Visual Studio 2010 Beta 2).

The error related to "TeamReview.VSNetAddIn.Addin", with:

System.InvalidOperationException: Method failed with unexpected error code 3.

This error message is not very helpful, so I decided to use my friends Reflector and LinqPad to help me look for the offending code and then quickly execute and replicate the exception.

To cut a long story short, I discovered that the exception occurs under Windows 7 when the following Visual Studio add-in folder does not exist:

C:\Users[Your User Name]\AppData\Roaming\Microsoft\MSEnvShared\Addins

This equates to:


The problem also happens on Windows XP:

C:\Documents and Settings[Your User Name]\Application Data\Microsoft\MSEnvShared\AddIns

In order to resolve the issue, manually create the folders through Windows Explorer or run the following command:

mkdir %APPDATA%\Microsoft\MSEnvShared\AddIns

Another work colleague has now raised this issue on the TeamReview CodePlex site.

Lessons In Domain-Driven Design - Basic Overview

   Submit to Reddit      

Recently I wanted to gain a clear, basic overview of Domain-Driven Design, and I stumbled upon Domain-Driven Design Pattern Summaries document from which is an excerpt of the book Domain-Driven Design, Addison-Wesley, by Eric Evans, 2004. The summaries document is licensed under the Creative Commons Deed: Attribution 2.0.

I also watched a presentation by Eric Evans entitled "What I learned about DDD since the book".

After studying the material, I drew a simple diagram to illustrate the Domain Model, in a way that made sense to me.

A Domain Model is a sphere of knowledge.

A Value Object contains a number of attributes that describes an object, but does not provide a mechanism to uniquely identify it.

An Entity is essentially an object that has a specific unique identity.

An Aggregate is a composition of a number of Entities and Value Objects, with one specific Entity being the root/parent/master.

A Repository encapsulates the data access functionality of Aggregates and can emulate access to a collection of objects. The role of the Repository is to provide an object-oriented view of the persistence layer and translate the object-oriented Domain Model to the physical data store.

A Domain Service is used for processes or transformations in the domain that are not the responsibility of an Entity or Value Object.

A Domain Event is some event that occurs that is important to be noted by a Domain Expert. An event happens and the effect is that state is changed.

Lessons In TFS Work Item Customisation - System.State Is Special

   Submit to Reddit      

I was customising some TFS 2008 Work Items, and I wanted to automate it so that the System.State value changes to a new state value when a custom field is changed to a specific value.

Quite simply, you can't do this. The System.State field cannot have a value copied into it, or have other actions done to it.

If you are serious about automating like this, the only workaround is to create a custom program that listens for a particular event or custom action, and then use the rich TFS API and programmatically change the value of System.State.

The same applies to System.Reason.