5
votes

I set up OpenCover in my MSBuild script, setup the ReportGenerator, and have it output as an artifact and have a custom tab - all of that works great. Here is my MSBuild target:

<Target Name="Test">

        <!-- Check Code Coverage -->
        <Exec Command="..\..\tools\OpenCover.4.0.519\OpenCover.Console.exe -register:user -target:..\..\tools\NUnit\nunit-console.exe -targetargs:&quot;$(TestAssemblies) /xml=NUnitReport.xml /noshadow&quot; -filter:&quot;+[HelloWorld.Mvc3UI*]* -[HelloWorld.Mvc3UI.UnitTests*]*&quot; -output:OpenCoverReport.xml"></Exec>

        <!-- Format Code Coverage Report -->
        <Exec Command="..\..\tools\ReportGenerator.1.5.0.0\ReportGenerator.exe OpenCoverReport.xml OpenCoverReport"></Exec>

</Target>

However, in order to run OpenCover it attaches to the NUnit runner to produce the report, which in turn runs all of the unit tests. While this can produce an xml output for the unit tests, I have yet to find an xsl file to produce reports as good as the ones built into TeamCity 7.1, much less the filtering and searching capabilities.

But if I enable the reports in TeamCity using the built-in NUnit runner (aparently the only way to get the unit test report in TeamCity), it re-runs the unit tests to generate its report.

While all this works, my question is whether there is a way to get both reports without having to run all of the unit tests twice? Specifically, can OpenCover generate its report without running the NUnit tests or can TeamCity generate its report without running the unit tests?

Note that this is an ASP.NET MVC3 application, and the OpenCover documentation doesn't specify how to attach ASP.NET or whether it is even possible, but it is pretty clear it requires an executable to attach to. Note also I am using NUnit 2.6.1 in case that matters.

1
Why do not you use dotCover? It's great tool which is shipped free with TeamCity.Pavel Bakshy
Thanks for the tip - I didn't realize it was free with TeamCity.NightOwl888
No problem, but for case with Opencover test please answer below.Pavel Bakshy

1 Answers

7
votes

You can import NUnit xml report using 'Build Feature' as showed on screen shot below: enter image description here