Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable Code Coverage for .NET Standard Library (2.0) project in VSTS (CI)

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

like image 589
Debasis Ghosh Avatar asked Jan 14 '18 20:01

Debasis Ghosh


1 Answers

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

like image 162
starian chen-MSFT Avatar answered Oct 18 '22 20:10

starian chen-MSFT