Sunday, October 2, 2011

Adding OpenCover to TeamCity

Adding OpenCover to the latest version of TeamCity (6.5) couldn't be easier however if you need help follow these simple steps.

1) Download and install OpenCover
2) Download and install ReportGenerator (actually unzip)
3) Register the OpenCover profiler DLLs using the regsvr32 utility

regsvr32 /s x86\OpenCover.Profiler.dll

regsvr32 /s x64\OpenCover.Profiler.dll


4) Using TeamCity add a new Build Step to your configuration
5) Choose Command Line as the runner type then choose Custom Script for the Run option.
6) Now all is needed is to set up the command to run the profiler against your tests e.g. for OpenCover the working directory is set to main\bin\debug and so we have

"%env.ProgramFiles(x86)%\opencover\opencover.console.exe" "-target:..\..\..\tools\NUnit-2.5.10.11092\bin\net-2.0\nunit-console-x86.exe" -targetargs:"OpenCover.Test.dll /noshadow" -filter:"+[Open*]* -[OpenCover.T*]*" "-output:..\..\..\opencovertests.xml"

"%env.ProgramFiles(x86)%\ReportGenerator\bin\ReportGenerator.exe" ..\..\..\opencovertests.xml ..\..\..\coverage


7) Finally setup the artifacts so that you can view the results in TeamCity e.g.


%teamcity.build.workingDir%\opencovertests.xml

%teamcity.build.workingDir%\coverage\**\*.*


And there you have it, OpenCover running under TeamCity and visual reports provided by ReportGenerator. I am sure you will find ways to improve upon this for your own builds.

10 comments:

  1. I've added support for OpenCover to Uppercut, a NAnt-based framework for getting CI builds up and running quickly. It works quite well with both TeamCity and CruiseControl.NET.

    Keep up the good work with OpenCover, it's about time we had an open source code coverage tool!

    ReplyDelete
  2. OpenCover and ReportGenerator should be registered on the Teamcity Agent right?

    Btw, Is it possible to do this without registering them?

    As David said, keep up the good work!

    ReplyDelete
  3. If you want to use them on team city then they need to be made available. OpenCover will need its profilers registering because team city uses a service account and you can't, to my knowledge, use local (user) registration with a COM object.

    ReplyDelete
  4. Would OpenCover be compatiable with older versions of TeamCity in this way? Specifically, 5.1?

    ReplyDelete
  5. I don't see why not. OpenCover is just a console application so assuming you can execute a console application from TeamCity 5.1 then it should be quite similar.

    ReplyDelete
  6. Great. Before I found this article, I already got OpenCover working with TeamCity using an MSBuild configuration file and using the MSBuild runner. However, what I am wondering is how I can use this in conjunction with TeamCity's built-in NUnit runner? Is it possible to get the results of OpenCover without running NUnit (in an ASP.NET MVC project)? I am just trying to avoid having to run the unit tests twice to get both the OpenCover report and the TeamCity NUnit report.

    See my StackOverflow question for more info: http://stackoverflow.com/questions/12058935/how-do-i-run-opencover-nunit-in-teamcity-without-running-all-unit-tests-twice

    ReplyDelete
  7. I see you got an answer from SO :)

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. This does method does not include the opencover report in the statistics tab of TeamCity (at build configuration level) as it is done when dotCover is used for example. Did anybody manage to include opencover results on the Statistics tab?

    ReplyDelete
  10. Caesars Palace Casino | Mapyro
    Find 통영 출장마사지 all Casinos near Caesars Palace Casino, Atlantic 여주 출장안마 City 계룡 출장샵 in realtime at Mapyro. 문경 출장샵 Use our live 충청북도 출장샵 traffic updates to see realtime driving directions,

    ReplyDelete