Integration of OpenCover with TFS

1.9k views Asked by At

I am new to TFS and want to integrate OpenCover with TFS. If any has done this please help!

4

There are 4 answers

0
Shaun Wilde On

OpenCover is just a console application so you can just modify your scripts to get OpenCover to run your unit tests.

I haven't used TFS for several years and it has changed since then however this blog post should help

To incorporate coverage measurement of OpenCover the build process of TFS (second half)

The original is in Japanese but if you are familiar with TFS then the screens will probably be obvious.

OpenCover also comes with an MSBuild task that may help you with your integration.

0
Robert K On

This question is rather old but maybe you are still interested. With current Version of TFS (2015 Update 2) this is now possible as a "vsts Extension".

See here for details: https://github.com/RobertK66/vsts-opencover

0
Naim Raja Díaz On

I've just integrated opencover with TFS Build, to generate a xml with the results that will be processed by sonar:

There is the cmd contents:

@REM @echo suppresses command line. ^ is line continuation character
@ECHO Executing OpenCover...
OpenCover.Console.exe -register:user ^
-target:"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe" ^
-targetargs:"/testcontainer:%~dp0test.dll /usestderr /resultsfile:%~dp0MSTestsResults.trx" ^
-output:%~dp0opencovertests.xml

But i'm facing three issues (that are related with my concrete implementation, but you may face them):

  1. The Tests are runned twice (one for template itself, and other for OpenCover)
  2. The MsTest.exe in the TFS Servers is not in the same path, so when the Controller asigns an agent (if the match is done by tags) then if the agent executing the build is in a TFS Server that does not have the MSTest in the right path it will fail.
  3. How to inject in cmd the corresponding test runner (MsTest, XUnit, Nunit, etc...) depending on the test project

Hope that it helps! (and someone can help me ;-)

0
milosz On

Since the answer doesn't specify the version of TFS, here is an answer for 2015/2017.

OpenCover can be run from TFS using the Powershell build step. You need to get the contents of the OpenCover NuGet package onto TFS and run OpenCover.console.exe from there.

Since TFS doesn't support the format produced by OpenCover, you need to take one additional step and convert the results to Cobertura format. It's possible using the OpenCoverToCoberturaConverter NuGet package.

I've described the whole process in much more detail on my blog:

http://codewithstyle.info/setting-up-coverage-reports-on-vsts-with-opencover/