问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/50126183/adding-code-coverage-of-net-core-xunit-project-to-vsts-build