How to use code coverage tools in continuous build integration of TFS 2013? - tfs

I am using the TFS 2013\VS 2013 professional editions for continuous build. Am looking to use an open source tool like OpenCover for code coverage. I have no prior experience in code coverage tools. I installed the OpenCover UI from Nuget but not sure how to include Codecoverage in integrated build in TFS. Getting "No Code Coverage Results" when the build runs.
I enabled code coverage under Automated tests node in build definition.
Any suggestion on how to implement code coverage in TFS\VS 2013 Profession edition would be greatly appreciated.

If you mean Enabled Code Coverage in the build definition just like below screeshot.
This is VS build-in code coverage, according to the Compare VS offerings site, only Visual Studio Enterprise has Code Coverage feature, so if you use TFS for your CI build and want to use the built-in code coverage feature, installing VS Enterprise on your build agent machine is required.
If you want to integrate OpenCover with TFS XAML build, you need to customize your build process template, add a custom activity in the build definition to trigger the opencover command for generating the report.
Created a RunCoverage.cmd at the root of my source folder
Installed / copied in TFS Servers the Opencover binaries and added into Path(must restart TFS Services to enable TFS to see it).
Created a new actitivity in the build definition, that is, editing the build template (before sonar execution activity) to run the cmd:
Running command line statements from TFS custom activity
http://msdn.microsoft.com/en-us/library/gg265783.aspx
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
More details please refer Naim Raja Díaz's answer in this similar question:Integration of OpenCover with TFS 

Related

TFS Build 2015 "Warning: Unable to create DiaSession for..." NUnit

When trying to run the unit tests as a build step in TFS Build 2015 (vNext), I get the following warning:
Warning: Unable to create DiaSession for <assembly>
No source location data will be available for this assembly.
The test assembly is then run, but the unit tests inside fail because they can't locate the references, I'm assuming because of the 'No source location data will be available' part of the warning.
The NUnit NuGet package I am using for the unit tests is: "NUnitTestAdapter.WithFramework" v2.0.0. The project is made in C#.
I've seen this question, but I don't really understand what they are saying, and it doesn't look like they are using TFS Build 2015 (vNext) build definitions.
Any ideas?
The question you referenced is talking about the old TFS build XAML not vNext build the one you are using.
However you could also use the same MSBuild arguments in vNext Visual Stduio Build or MSbuild task.
You need to use add the /p:NoWarn=warningNumber in MSBuild Arguments
in the build definition. Or use the /p:WarningLevel=0 argument to
suppress all warnings.
According to your error info, seems the issue should not related to TFS build side. Since unit tests inside fail because they can't locate the references, please try to directly run your tests on the build agent locally(remote to). This will help you to narrow down the issue. Besides, also Enable Verbose Debug Mode for TFS Build vNext by adding system.debug=true to see if there are more details log info for troubleshooting.

How to run C++ tests based on GoogleTest with TFS 2015

We have a Visual Studio 2015 solution containing some C++ projects and some tests based on Google Test Framework.
Now I would like to run those tests with the quite new TFS 2015 build features. I know that there is the "Visual Studio Test" build step that is able to run custom test adapters (like the Google Test Adapter?).
Is this the easiest way to setup things? What exactly has to be installed on the (on premise) TFS2015 build server and how to configure the build steps?
Thanks for you help! Sebastian
Yes, the simplest way is just using google test adapter in ""Visual Studio Test" build " task. Just as the feature statement which will using VSTest.Console.exe
You need to install visual studio on your build server(agent). About how to conigure the build steps, there has been a detailed tutorial with Xunit test which also applies to google test. Plesae refer this blog: Running xUnit tests in TFS Build vNext

No code coverage in TFS build after 2015 upgrade

We were using TFS and VS 2013, everything was working fine. We upgraded to TFS and VS 2015. We added a new build server (Windows Server 2012 R2, Visual Studio 2015 Enterprise, DevExpress and Wix) to have a clean install.
The builds were failing Task could not find "LC.exe" using the SdkToolsPath "" ... so we changed the build template from DefaultTemplate.11.1.xaml to TfvcTemplate.12.xaml
Now it's building, but when we open the builds from the build explorer under code coverage we have No build code coverage data available. Code coverage is enabled in the build definition.
Assuming you enabled Code coverage by going to the process tab of the build definition and then expanding the Tests--Automated tests--Test Source--Run settings, and change the Type of run settings from Default to CodeCoverageEnabled.
I have tried the same steps in TFS 2015, and I can't get Code coverage either in this way.
Instead, I tried the steps below, then I can get Code coverage now:
Go to Process--Test--Automated tests--Test source in build definition.
Now in Test source row, click the button with "...".
Under "Options", select Enabled Code Coverage and save the build definition. No matter the Enabled Code Coverage option has been selected or not, you still need to save this edit. Now queue the build, you'll see the code coverage.

Integration of OpenCover with TFS

I am new to TFS and want to integrate OpenCover with TFS. If any has done this please help!
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
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/
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.
I've just integrated opencover with TFS Build, to generate a xml with the results that will be processed by sonar:
Created a RunCoverage.cmd at the root of my source folder
Installed / copied in TFS Servers the Opencover binaries and added into Path(must restart TFS Services to enable TFS to see it).
Created a new actitivity in the build definition, that is, editing the build template (before sonar execution activity) to run the cmd:
Running command line statements from TFS custom activity
http://msdn.microsoft.com/en-us/library/gg265783.aspx
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):
The Tests are runned twice (one for template itself, and other for OpenCover)
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.
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 ;-)

Code Coverage possible for TFS Build 2008 building Visual Studio 2010 Project?

We have moved to Visual Studio 2010 but our TFS folks are not ready yet. After some work, we can get the build to work, but we don't get code coverage.
We are running using the MSTest test runner. Does anyone know any tricks to get TFS to report code coverage using Visual Studio 2010 on a build server that has a TFS 2008 Build agent?
There is command line tool that name is VsPerfMon.
Whit this tool you can run your code coverage via command line. You can check this link for more information, http://msdn.microsoft.com/en-us/library/ms182404(VS.80).aspx
So if you can run code coverage via command line, you can invoke this tool via TFS 2008 Build Scripts.

Resources