blogs.conchango.com

welcome to the conchango blogging site
Welcome to blogs.conchango.com Sign in | Join | Help
in Search

Howard van Rooijen's Blog

Making Code Coverage more palatable with NCoverViewer and NCoverBrowser

This is an extract from an internal How To document I wrote for our .netFusion development framework documentation.


  1. Download NCover and extract to C:\Program Files\NCover
  2. Download NCoverGUI and extract to C:\Program Files\NCoverGui
  3. Replace NCover\Coverage.xsl and NCoverGui\Coverage.xsl with Yves Lorphelin’s improved stylesheet (as the default stylesheet is not very user-friendly)

Code Coverage:

  1. From the green bars in NUnit, we know we have passing tests – but how much of our Stack  implementation is actually being tested? Start C:\Program Files\NCoverGui\NCoverGui.exe and configure it as in the screenshot below:

NCoverGUI configuration

NCover is a command line code coverage tool that profiles a running application using the .NET CLR profiling API. In the case above we are using NCover to monitor assemblies that are being called by NUnit.

  • Application to Profile – this should be the path to the NUnit console application
  • Working Directory – this is pretty self explanatory
  • Application Arguments – these are the arguments that are going to be passed to the NUnit console application
  • Assemblies to watch – this lists the assemblies that will actually be profiled by NCover. This has to be the Name of the Type rather than the name of the assembly thus, in the example above Conchango.UnitTest.Example is entered rather than Conchango.UnitTest.Example.dll. All assemblies listed must have debugging information (.pdb files) available in the same directory as the assembly. If you select All that have debug symbols – you  will get coverage information about the unit tests as well as the assembly you are unit testing
  • Display coverage report when complete – this lists the location and the name of the report to be generated

If you wanted to run NCover from the command line, the equivalent to the options above is:

NCover.Console /o "C:\Projects\Conchango\BrownBagSessions\Conchango.UnitTest.Example.Fixtures\Example.Fixtures.Coverage.xml" /c "C:\Program Files\NUnit 2.2\bin\nunit-console.exe" "C:\Projects\Conchango\BrownBagSessions\Conchango.UnitTest.Example.Fixtures\bin\Debug\Conchango.UnitTest.Example.Fixtures.dll" /a "Conchango.UnitTest.Example"

Where

  • /o means output the report to thefollowing file
  • /c means launch the application to be profiled. In the case about the application is NUnit, which in turn runs the Conchango.UnitTest.Example.Fixtures.dll (which references Conchango.UnitTest.Example.dll)
  • /a means the assemblies to profile, so this will be Conchango.UnitTest.Example NOTE: the assembly name is case sensitive.

The above will produce the following output:

NCover Command Prompt output

  1. Navigate to C:\Projects\Conchango\BrownBagSessions\Conchango.UnitTest.Example.Fixtures\Example.Fixtures.Coverage.xml to browse the output file.

Back to NCoverGui: Click the Profile button – there should be a short pause, a command prompt will be launched; this will run NUnit in console mode and then exit. A new web browser should appear with the coverage test results:

NCover Coverage report (using Yves Lorphelin's stylesheet) - summary 

The coverage report shows that only 80% of the code is being executed by the unit tests we have written – the Top method is the culprit

NCover Coverage report (using Yves Lorphelin's stylesheet) - details

The Visits column highlights in red the lines of code have not been visited during the execution of the unit tests. If you navigate to line 27 in Stack.cs you’ll see that

return this.elements[0];
}

are the lines that haven’t been executed as our test throws a InvalidOperationException and then exits the method, without calling these two lines.

Although this is very informative, tabbing between Visual Studio, and IE it’s not a very productive way of looking at code coverage – there is another tool called NCoverBrowser which give a more integrated view of the coverage results. Download, unzip and run the application.

  1. Select File > Open and then select the coverage report C:\Projects\Conchango\BrownBagSessions\Conchango.UnitTest.Example.Fixtures\Example.Fixtures.Coverage.xml

The screenshot below shows the result, note how

return this.elements[0];

is underlined in red:

NCover Browser screen shot 

This is a much clearer method for monitoring the code coverage results.

Published 22 November 2004 14:40 by howard.vanrooijen

Comments

 

TrackBack said:

December 7, 2004 12:21
 

TrackBack said:

December 7, 2004 15:16
 

TrackBack said:

[Cool Thing of the Day] Netron Light Framework
January 26, 2005 08:40
 

TrackBack said:

Unit Testing and Code Coverage
February 1, 2005 21:33
 

howard.vanrooijen said:

Right after I hit PROFILE, the cmd window appears and the tests appear to run, but I get a message that the report is not in the proper location. A TestReport.xml file is generated in the same folder as the assembly, but it does not seem to get moved or renamed.
April 15, 2005 23:15
 

TrackBack said:

June 14, 2005 13:14
 

howard.vanrooijen said:

Perfect!
June 14, 2005 15:50
 

Howard van Rooijen's Blog said:

Here is the slide deck I presented at the Microsoft Architect Forum yesterday. I've included the notes...
July 3, 2005 18:09
 

Hari Vignesh said:

"Right after I hit PROFILE, the cmd window appears and the tests appear to run, but I get a message that the report is not in the proper location. A TestReport.xml file is generated in the same folder as the assembly, but it does not seem to get moved or renamed.
Steve Lewis "

Hi Steve, I had teh same problem. It was because I was using the latest alpha release of ncover (v1.4.6) and not the stable version. If you change to the stable version (v1.3.3) , that will solve teh problem.
July 22, 2005 22:43
 

Richard Griffin's Blog said:

Following on from Howards recent post with regards to the use of Simian in VS 2005\3, I thought...
February 8, 2006 19:07
 

Richard Griffin's Blog said:

Following on from Howards recent post with regards to the use of Simian in VS 2005\3, I thought...
February 8, 2006 19:26
 

diazepam generic said:

geuger oqazoh

August 16, 2007 22:46
New Comments to this post are disabled
Powered by Community Server (Personal Edition), by Telligent Systems