5

Please help me - How do I enable/show code coverage result for .NET Standard library project (2.0) in VSTS (CI). Have enable Test result through dotnet Test task (.NET Core 2.0 preview) and able to to see the passed Test cases. Next step I have added "publish result" task but it's showing the below warning during Build - No test result files matching _temp*/.trx were found. Even I have modified the .csproj file and added <DebugType>Full</DebugType>.

Using Visual Studio 2017 Professional (version - 15.5.2) Project - .NET Standard Library (2.0) Unit Test - MSTest (inbuilt in Visual Studio)

What tasks / how tasks should I need to add/modify in Build Definition in VSTS, so that I can see Code Coverage against Unit Testing.

Tasks for Code Coverage - TestAssemblies

other option

Now I am able to see the Code Coverage (not sure whether correct code coverage is showing or not) but the tasks - Test Assemblies ***.test*.dll is failing with the below error - Code-Coverage-Result

  • No test is available in .........$(BuildConfiguration)\netcoreapp2.0\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate and try again.

    • No test is available in ...... $(BuildConfiguration)\netcoreapp2.0\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate and try again.

Thanks.

Regards, Deb

Debasis Ghosh
  • 263
  • 3
  • 21

1 Answers1

4

First, make sure you can get code coverage result through Visual Studio. As far as I know, Enterprise version is required (You can use Hosted VS 2017 agent).

The Code Coverage for .Net Core Unit test project:

  1. Add <DebugType>Full</DebugType> to PreopertyGroup

Sample:

<PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>

    <IsPackable>false</IsPackable>
    <DebugType>Full</DebugType>
  </PropertyGroup>
  1. Install Microsoft.CodeCoverage package to test project

Secondly, you can run test through Visual Studio Test task: (

Path to vstest.console.exe: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe

Check Code coverage enabled option

Other console options: /framework:".NETCoreApp,Version=v2.0")

enter image description here

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
  • Hi starian, First of all I am using VS Professional ver. 15.5.2. not using Enterprise Edition. Completed the Point No 1 and Point 2 as you stated above. Please help me How do I get code coverage result in VSTS; i.e. which tasks do I need to add in Build Definition that will show / support the code coverage after build completion in VSTS (CI) for .NET Standard Library (version 2.0) project. Thanks. Deb – Debasis Ghosh Jan 15 '18 at 13:15
  • Can you get code coverage result through Visual Studio? Based on this article (https://www.visualstudio.com/vs/compare/), just Enterprise version supports Code coverage). Using Visual Studio Test task (Check second point of my answer) – starian chen-MSFT Jan 16 '18 at 01:23
  • I am using VS professional, so unable to do code coverage locally. Secondly I have followed what you have mentioned, unable to find vstest.console.exe as I am using vs professional. So I want to enable code coverage in VSTS (VisualStudio.com --> Build --> Build Definition). Please tell me which tasks should I need to add in Build Definition to get the Code coverage for .NET Standard Library 2.0. Thanks. – Debasis Ghosh Jan 17 '18 at 05:16
  • @DebasisGhosh It is Visual Studio Test Task, check the screenshot in my answer. Also you need to use Hosted VS 2017 agent. – starian chen-MSFT Jan 17 '18 at 05:29
  • thank for your help. Now i am getting the below errors, though i have installed the prerequisite packages and all unit test are passed in local VS 2017. Test Assemblies **\*.test*.dll - Data collector 'Code Coverage' message: Failed to launch CodeCoverage.exe. No code coverage will be collected.. No test is available in ..\release\netcoreapp2.0\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate and try again. Thanks - Deb – Debasis Ghosh Jan 17 '18 at 18:55
  • though I have added into the project. Not sure which pacakges I need to install again. Thanks. Deb – Debasis Ghosh Jan 17 '18 at 18:57
  • @DebasisGhosh specify `**\*Test*.dll !**\*TestAdapter*.dll !**\obj\**` (three lines) in Test assemblies box of Visual Studio Test task to exclude necessary dll files (e.g. Microsoft.VisualStudio.TestPlatform‌​.MSTestAdapter.Platf‌​ormServices.Interfac‌​e.dll). – starian chen-MSFT Jan 18 '18 at 01:35
  • already added three lines in Test assemblies, though I am getting the same issue. Please check - uploaded the tasks screenshot in Tasks for Code Coverage - TestAssemblies – Debasis Ghosh Jan 18 '18 at 03:15
  • Replace `!**\*TestAdapter.dll` to `!**\*TestAdapter*.dll`. – starian chen-MSFT Jan 18 '18 at 05:19
  • Wow! Thank you very much for your help and support. Now build got succeeded. Excluded these files - !**\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll !**\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll. Will try - !**\*TestAdapter*.dll. Thanks - Deb – Debasis Ghosh Jan 18 '18 at 05:32