I'd like to add the code coverage metrics to our VSTS build. The solution is ASP.NET core with XUnit. Please advise on the steps.
Asked
Active
Viewed 1,690 times
1
-
At the top of the page clearly the information is provided. – Lex Li May 02 '18 at 02:05
-
Thanks for downvoting. Do you refer to this link? https://github.com/Microsoft/vsts-tasks/blob/master/Tasks/VsTest/README.md – Boris Lipschitz May 02 '18 at 02:10
-
if yes, then point me how to enable code coverage for the .net core projects – Boris Lipschitz May 02 '18 at 02:12
-
Combining all keywords in the message, Google can easily lead you to threads like https://github.com/Microsoft/vstest/issues/579 Microsoft is still far from making everything ready. – Lex Li May 02 '18 at 02:31
-
Possible duplicate of [Code coverage and test results for dotnet core projects in VSTS](https://stackoverflow.com/questions/46159067/code-coverage-and-test-results-for-dotnet-core-projects-in-vsts) – Lex Li May 02 '18 at 02:31
-
I saw that link as well, however, my question is more relevant to XUnit rather than MSTests and besides there is no clear answer. In any case, there is no "At the top of the page clearly the information is provided". I'd prefer, someone knowledgeable from VSTS team answer my question – Boris Lipschitz May 02 '18 at 02:39
-
Do you solve this issue? – starian chen-MSFT May 16 '18 at 05:37
1 Answers
2
Refer to these steps to enable code coverage for .NET Core XUnit test:
- Edit projects’ files (test and related project) to add DebugType property
for example:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
<DebugType>Full</DebugType>
</PropertyGroup>
- Update Microsoft.NET.Test.Sdk package to latest version (change version value to 15.7.0)
- Add Visual Studio Test task to build definition and specify Test assemblies and Search folder
- Choose Specific location option in Select test platform using section
- Specify
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform
in Path to vstest.console.exe - Check Code coverage enabled option
- Specify
/framework:".NETCoreApp,Version=v2.0"
in Other console options box

starian chen-MSFT
- 33,174
- 2
- 29
- 53
-
Thanks! I wonder if it works with Test assemblies should I "dotnet publish" first? – Boris Lipschitz May 03 '18 at 02:52
-
-
You are right about no need to publish. However, it doesn't work:Data collector 'Code Coverage' message: Cannot find CodeCoverage.exe.. FileNotFoundException: No test is available in C:\agent\_work\2\s\test\MyProj.UnitTests\obj\release\netcoreapp2.0\MyProj.UnitTests.dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate and try again. – Boris Lipschitz May 03 '18 at 03:22
-
-
What're tasks of your build definition? Can you share the detail log on the OneDrive? (Set system.debug variable to true, then queue build and share this log) Try to specify` **\*UnitTest*.dll !**\obj\**` (two lines) in Test assemblies input box. – starian chen-MSFT May 03 '18 at 05:11
-
-
What's the result if you build it through Hosted VS 2017 agent? Can you reproduce this issue with a new project? if so, you can share the sample project on the OneDrive. – starian chen-MSFT May 03 '18 at 05:43
-
So, the Coverage works with the Hosted Build! (I've uploaded the logs to onedrive). So, what could be the problem with the on-prem agent? One difference is our on-prem build has Professional VS installed. – Boris Lipschitz May 03 '18 at 06:28
-
-
Oh my gosh! To create code coverage in VSTS you have to use VS2017 Enterpise... I would have hoped that code coverage of VSTS isn't dependant on the version of the installed IDE... – Boris Lipschitz May 03 '18 at 06:42
-
It's a bit of waste of money to use VS Enterprise edition to run on a build server... :) – Boris Lipschitz May 03 '18 at 06:45
-
@BorisLipschitz VS enterprise version is required, but you can use Hosted Agent. – starian chen-MSFT May 03 '18 at 07:02
-
No, we have on-prem build and I don't want to waste the Enterprise licence for the Build Server – Boris Lipschitz May 17 '18 at 06:05
-
-
Hosted Agent is out of the question, as my Integration tests require resources that are not available on the Hosted Agent – Boris Lipschitz May 17 '18 at 23:52
-
What's the result if you install VS enterprise without licence on build server? – starian chen-MSFT May 18 '18 at 01:40
-
@starianchen-MSFT what does `
Full ` do? Is it safe if I enable this for a package that will get published on Nuget? – El Mac Jul 12 '18 at 18:29