Why can't I get 100% code coverage on a method that calls a constructor of a generic type?
- by Martin Watts
Today I came across a wierd issue in a Visual Studio 2008 Code Coverage Analysis.
Consider the following method:
private IController GetController<T>(IContext context) where T : IController, new()
{
IController controller = new T();
controller.ListeningContext = context;
controller.Plugin = this;
return controller;
}
This method is called in a unit test as follows (MenuController has an empty constructor):
controller = plugin.GetController<MenuController>(null);
After calling this method from a Unit Test, the following code coverage report is generated:
As you can see, Code Coverage is only 85%. Looking up the code results in the following:
Apparently, the call to the constructor of the generic type is considered only partly covered.
WHY? Google didn't help. And MSDN didn't help at all, of course. Anybody who does know?