1

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.

enter image description here enter image description here

7

1 Answer 1

2

Refer to these steps to enable code coverage for .NET Core XUnit test:

  1. 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>
  1. Update Microsoft.NET.Test.Sdk package to latest version (change version value to 15.7.0)
  2. Add Visual Studio Test task to build definition and specify Test assemblies and Search folder
  3. Choose Specific location option in Select test platform using section
  4. Specify C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform in Path to vstest.console.exe
  5. Check Code coverage enabled option
  6. Specify /framework:".NETCoreApp,Version=v2.0" in Other console options box
Sign up to request clarification or add additional context in comments.

17 Comments

Thanks! I wonder if it works with Test assemblies should I "dotnet publish" first?
@BorisLipschitz Do not need.
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.
I do have <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.