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.
7
-
At the top of the page clearly the information is provided.Lex Li– Lex Li2018-05-02 02:05:43 +00:00Commented May 2, 2018 at 2:05
-
Thanks for downvoting. Do you refer to this link? github.com/Microsoft/vsts-tasks/blob/master/Tasks/VsTest/…Boris Lipschitz– Boris Lipschitz2018-05-02 02:10:15 +00:00Commented May 2, 2018 at 2:10
-
if yes, then point me how to enable code coverage for the .net core projectsBoris Lipschitz– Boris Lipschitz2018-05-02 02:12:01 +00:00Commented May 2, 2018 at 2:12
-
Combining all keywords in the message, Google can easily lead you to threads like github.com/Microsoft/vstest/issues/579 Microsoft is still far from making everything ready.Lex Li– Lex Li2018-05-02 02:31:43 +00:00Commented May 2, 2018 at 2:31
-
Possible duplicate of Code coverage and test results for dotnet core projects in VSTSLex Li– Lex Li2018-05-02 02:31:51 +00:00Commented May 2, 2018 at 2:31
|
Show 2 more comments
1 Answer
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\TestPlatformin Path to vstest.console.exe - Check Code coverage enabled option
- Specify
/framework:".NETCoreApp,Version=v2.0"in Other console options box
17 Comments
Boris Lipschitz
Thanks! I wonder if it works with Test assemblies should I "dotnet publish" first?
starian chen-MSFT
@BorisLipschitz Do not need.
Boris Lipschitz
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
I do have <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
starian chen-MSFT
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.
|

