Monday, February 12, 2007

NCover Setup - Part I

About a year ago, one of my projects established some best practices for test-driven development where we found our sweet spot using .NET 1.1, NUnit, NCover and NCoverBrowser. Things were going great until one day, NCover stopped producing coverage reports. Despite my best efforts, I couldn't get it working again. Panic. Frustration. Pain. Despair. Acceptance: no more coverage reports....

Now, a new project is about to take off, this one using .NET 2.0, and I'm determined to get NCover running on this project. Problem is, documentation for NCover is still no where to be found online, only mixed messages in their forums.

So, for my reference, and potentially yours, I thought I'd share how I set this up. As I'm building an application for an enterprise the requirements can get pretty complex... here's what I'm shooting for:

  1. I typically structure a project so that I have a solution folder which contains copies of all the libraries my project will require to compile. I also bundle third-party tools with the solution folder so that when a developer checks the project out of source-control, the build script has everything it needs to operate without any configuration on behalf of the developer.
  2. I want to structure the solution so that the application code and the test harness are in different assemblies.
  3. In addition to separate test and application assemblies, configuration settings from the application code must be used with the test harness.
  4. I need to drive the code coverage from a NAnt script
  5. I need to integrate the output into CruiseControl.NET

So I downloaded NCover 1.5.5 beta and cracked open a new ClassLibrary project to simulate code coverage. I wrote two classes: a simple class "Core.Class1" and a test fixture "Test.Class1Test". I compiled the solution, dropped to a command prompt and manually tried to execute ncover using relative file paths. "Unable to locate file" errors.

As soon as I put both NCover and NUnit file paths into my PATH environment variable, the error messages started to change. The following statement, executed from the "bin\Debug" folder of my project:

"ncover.console nunit-console Core.dll //a Core"
...worked!

Although adding PATH variables violates objective #1 it did produce a coverage report for the Core and Test namespaces. Since my NUnit test cases are guaranteed to be 100% covered by NUnit, I'll need to find a way to exclude the Test namespace from the report.

I'll reorganize the project into separate assemblies and see how that changes this configuration tommorrow.

Read part two: NCover Setup - Part II

submit to reddit

3 comments:

kiwidude said...

You might want to try NCoverExplorer rather than NCoverBrowser. It has NAnt/MSBuild tasks for running NCover, improved CC.Net stylesheets and numerous other goodies. Blog and downloads are at http://www.kiwidude.com/blog/

As far as NCover documentation goes, there is an updated FAQ at http://www.kiwidude.com/dotnet/NCoverFAQ.html

I would be wary of using NCover 1.5.5 - you are better off using 1.5.4 until 1.5.7 comes out.

bryan said...

Kiwidude,

You beat me to the punch-line! I was eyeing your project... ;-)

Thanks for the tips on the version numbers!

kiwidude said...

Oops - sorry mate ;-)

Ah well, looking forward to reading about what you liked, didn't like, any problems you had etc in Part II!

Sadly good quality documentation is hard to find on most open source projects and NCover & NCoverExplorer don't break that trend ;-)

I do hope to change that soon when a bit more time is freed up - there are so many little tips & tricks that are just begging for a wiki on this...

Grant.