1
votes

I am trying to run code coverage using Opencover for NUnit test cases. I am getting results as expected, but the problem is while executing opencover it is again running the tests. We don't want this to be happen as we are running the tests separately. Below is my code.

Unit test execution

<Exec Command="$(NUnit) @(AssembliesToTest->'&quot;%(FullPath)&quot;', ' ') /xml:&quot;@(TestsDirectory)Unit-nunit-results.xml&quot;" 
      ContinueOnError="false" />

OpenCover Execution

<Exec Command="$(OpenCoverExecutable) -register:user -target:$(NUnit) -targetargs:&quot;/noshadow %(CodeCoverageAssemblies.fullpath) /domain:single&quot; -mergeoutput -output:&quot;$(OutputPath)\OpenCover-results.xml&quot;" 
      ContinueOnError="false" />

Is there any way to get test and codecoverage results without executing tests twice.

Thanks in Advance,

Dinesh.

1

1 Answers

4
votes

Sorry the answer is no - OpenCover instruments your code as it executes to determine the code that is executed during the test.

Why don't you just use OpenCover to run your tests once. If you need to look at the errorcode of your test runner then you can use the -returntargetcode[:<opencoverreturncodeoffset>] such that the exit code of your target process is returned as the exit code of OpenCover and any OpenCover related exit codes are moved to the new range. e.g.

-returntargetcode:1000