Friday, November 18, 2011

Code coverage info from NUnit into Visual Studio

Use NCover or dotCover you might say. And you would be right.

But for the current project I was looking for a free solution. I started to google the web for a free alternative and found PartCover, OpenCover and this article.

PartCover and OpenCover does noe have any GUI or plugin in Visual Studio, so when I saw that it was possible to use the same window in VS as MSTest I was sold.

Run the following command in the visual studio prompt. (Add the correct paths and dlls for your system)

vsinstr -coverage MyLibrary.dll
start vsperfmon -coverage -output:mytestrun.coverage
nunit-console.exe /noshadow UnitTests.dll
vsperfcmd -shutdown
Whats happening here is that we are first adding instrumentation to the dll. Then we are starting the vsperfmon service to listen to whats beeing executed. Execute the test runner and shutdown the vsperfmon service.
Then open the mytestrun.coverage file in Visual Studio. Voila..

The Test coverage is displayed with the information.
I guess the only catch is that you need Team System Tools for this to work.
Off course you need to manually set this up. Hmm maybe I should write a Visual Studio plugin..

Share:

2 comments:

  1. Do you know of a way to publish the results INTO TFS so it can show up in the build summary report?

    ReplyDelete
    Replies
    1. I haven't had the need for this myself.
      But checkout this post http://blog.ovesens.net/2011/11/using-opencover-and-nunit-with-msbuild/

      Delete