xunit 2.4.1 使用 cli dotnet test --collect:"Code Coverage" 不生成覆盖率 xml
xunit 2.4.1 use cli dotnet test --collect:"Code Coverage" not generate coverage xml
我用了dotnet test --collect:"Code Coverage"
PS D:\git\MiniExcel\tests\MiniExcelTests> dotnet test --collect:"Code Coverage"
#...
Data collection : Unable to find a datacollector with friendly name 'Code Coverage'.
Data collection : Could not find data collector 'Code Coverage'
#...
那我也试过了
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
系统也不生成coverage.xml
我的测试csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0;net461</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
您必须参考 Microsoft.NET.Test.Sdk 中提到的 documentation
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
我用了dotnet test --collect:"Code Coverage"
PS D:\git\MiniExcel\tests\MiniExcelTests> dotnet test --collect:"Code Coverage"
#...
Data collection : Unable to find a datacollector with friendly name 'Code Coverage'.
Data collection : Could not find data collector 'Code Coverage'
#...
那我也试过了
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
系统也不生成coverage.xml
我的测试csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0;net461</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
您必须参考 Microsoft.NET.Test.Sdk 中提到的 documentation
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />