Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run OpenCover + NUnit in TeamCity without running all unit tests twice?

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.

like image 924
NightOwl888 Avatar asked Aug 21 '12 16:08

NightOwl888


1 Answers

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

like image 152
Pavel Bakshy Avatar answered Oct 17 '22 06:10

Pavel Bakshy