Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

NCover and NCoverExplorer – Bad News Is Empowering

Awhile back I mentioned how I had created a very simple ActiveRecord Framework for kicks one day. It was inspired by and uses a similar API to CastleProject's ActiveRecord, and I used the same attributes and schema as Linq for SQL, so I could take advantage of Linq for SQL's Visual Designer and SqlMetal for code generation.

Although it "works," I don't know how well it works. There are no unit tests, and I didn't do any profiling. It was one of those projects that you find yourself doing for fun just to see if you can on a rainy day. I have about a half-a-dozen similar "just-for-kicks" projects sitting on my laptop in the same state.

This weekend I decided to formalize a few of these projects, because a few of them are quite useful and I would like to continue building them and perhaps host them on CodePlex, etc.

The first thing I wanted to do was formalize the build process. I added my typical Nant targets and tasks, but decided to add one I have not done in the past – one that reported on the code coverage of my unit tests. Seems like it would certainly be useful to know just how much coverage I have on my unit tests. Even if the report could be interpreted as bad news, it would certainly be empowering and better than no news.

Two NCovers?

Now I knew about NCover, but had never played with it. As I searched for NCover, I noticed there are two NCovers? One at NCover.org ( which used to be on GotDotNet ) and one on SourceForge. Huh? Which one do you use?

Well, I am still not totally sure of why the two projects, but I used the one at NCover.org, because

  1. The one on SourceForge had to instrumentize my source code. This just didn't sound inviting regardless of how innocent the process may be.
  2. I stumbled upon NCoverExplorer, which had NAnt Tasks for NCover at NCover.org, and the report generated by NCoverExplorer looked mighty cool.

 

NCover NAnt Task

As I mentioned, NCoverExplorer has this really cool NAnt Task to run NCover. When you download the NCoverExplorer.Extras, unzip the folder and go into the bin folder and copy the following 2 files:

  1. NCoverExplorer.NAntTasks.dll
  2. NCoverExplorer.NAntTasks.xml

into your NAnt working directory so it can discover and pick up the new NCover and NCoverExplorer Tasks.

For my simple framework, the task looks as such:

 

<ncover program="tools\ncover\NCover.Console.exe"
    commandLineExe="tools\nunit\nunit-console.exe"
    commandLineArgs="Hayden.ActiveRecord.UnitTests.NUnit.dll /xml=Hayden.ActiveRecord.nunit.xml /labels /nologo"
    workingDirectory="${build.output.dir}"
    coverageFile="${reports.dir}\Hayden.ActiveRecord.ncover.xml"
    logLevel="Verbose"
    logFile="Hayden.ActiveRecord.ncover.log"
    verbose="true">
        <assemblies basedir="${build.output.dir}">
            <include name="Hayden.ActiveRecord.dll"/>
        </assemblies>
</ncover>

 

 I still have some learning here as to what I should be including in the task, but this at least got me up and running.

 

NCover Error: Connected Profiled process terminated. Profiler connection not established.

During your adventures with NCover, you may come across the following error:

"Connected Profiled process terminated. Profiler connection not established."

You will see this mentioned in the forums, but no really good answers as to how to fix it.

There may be multiple reasons why you could get this error, but the reason I received the error is because I didn't realize that during the NCover installation it registered a dll, called CoverLib.dll. If after installation you copy NCover to your tools folder for inclusion into source code and run it from there, you will get that error.

You need to do one of two things. Either 1) Run NCover-Console.exe from the location it was originally installed, which is where the CoverLib.dll was originally registered, or, 2) you need to unregister the original dll and re-register it from within the tools folder where you plan to run it. This fixed the problem for me.

 

NCoverExplorer

You can also use NCoverExplorer in your build by using a task similar to as follows:

 

<ncoverexplorer program="tools\ncoverexplorer\ncoverexplorer.console.exe"
    projectName="ActiveRecord"
    outputDir="${reports.dir}"
    satisfactoryCoverage="80"
    reportType="ModuleClassFunctionSummary"
    htmlReportName="CoverageSummary.html"
    showExcluded="True">
    <fileset>
        <include name="${reports.dir}\Hayden.ActiveRecord.ncover.xml" />
    </fileset>
</ncoverexplorer>

 

 Again, I have some more learning I need to do here, but this gave me a sweet looking report with some bad news :)

 

 

 

But even bad news is empowering!

 

This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

One Response to NCover and NCoverExplorer – Bad News Is Empowering

  1. kiwidude says:

    Always pleased to see another user posting about their experiences with NCoverExplorer – even when they do result in the bad news of showing how many more tests you need to write 😉

    Re the NCover versions – they are indeed two different projects. The NCover.org is the one you should use, it was originally at GotDotNet I believe before Peter moved it to it’s own domain. It is actively being developed although the pace has been pretty slow this year with Peter having some personal commitments limiting his time.

    The “other” project on SourceForge has long since died a death and is not compatible in any way. It was rather unfortunate they both used the same name – it confuses people continuously.

    The latest builds of my task should not require you to register CoverLib.dll – what build number are you using? They should self-register the .dll themselves for the duration of running coverage using a registry trick. The very latest build is 1.3.5.1861. If that’s what you have and it’s not working either drop me an email or please put a post on the forums at NCover.org and I will take another look at it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>