.NET 4.8下dotnet test无法找到XPlat Code Coverage的问题咨询
关于.NET 4.8下使用Coverlet进行代码覆盖率检测的问题
疑问1:Coverlet对SDK风格项目的要求范围
测试项目为SDK风格且已安装coverlet.collector,但部分被引用项目非SDK风格,项目基于.NET 4.8。想明确:Coverlet仅支持SDK风格项目的要求,是仅针对测试项目,还是包含所有被引用的项目?
问题2:针对DLL执行dotnet test时无法找到XPlat Code Coverage收集器
构建项目后,执行以下dotnet test命令直接针对测试DLL文件:
dotnet test C:\git\Repositories\xxxx\bin\AnyCPU\Release\Test\aaaaaaaa.dll --collect:"XPlat Code Coverage" --settings:CodeCoverage.runsettings --results-directory C:\git\Repositories\xxxx\TestResults --logger 'trx;LogFilePrefix=aaaaaaaaa.dll' -- RunConfiguration.TargetPlatform=x64 MSTest.DeploymentEnabled=false
运行时出现错误:
VERBOSE: Data collection : Unable to find a datacollector with friendly name 'XPlat Code Coverage'.
VERBOSE: Data collection : Could not find data collector 'XPlat Code Coverage'
已确认测试项目已引用coverlet.collector,但仍报错。此前在.NET 5+环境下针对csproj使用Coverlet无问题,但当前必须针对DLL执行测试且无法升级.NET版本,请问Coverlet在此场景下是否存在限制?
测试项目csproj配置
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net48</TargetFramework> <IsPackable>false</IsPackable> <RootNamespace>xxxxxxx</RootNamespace> <OutputPath>..\..\bin\$(Platform)\$(Configuration)\Test\Shared</OutputPath> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> <PackageReference Include="MSTest.TestAdapter" Version="3.0.4" /> <PackageReference Include="MSTest.TestFramework" Version="3.0.4" /> <PackageReference Include="ApprovalTests" Version="5.7.3" /> <PackageReference Include="ApprovalUtilities" Version="5.7.3" /> <PackageReference Include="System.Data.SqlClient" Version="4.8.5" /> <PackageReference Include="coverlet.collector" Version="6.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> </ItemGroup> <ItemGroup> <ProjectReference Include="xxxxxx.csproj" /> <ProjectReference Include="yyyyyy.csproj" /> </ItemGroup> <ItemGroup> <Compile Include="..\..\Properties\SharedAssemblyInfo.cs"> <Link>Properties\SharedAssemblyInfo.cs</Link> </Compile> </ItemGroup> <ItemGroup> <None Include="app.config" /> </ItemGroup> <Target Name="CopyApprovalFiles" AfterTargets="PostBuildEvent"> <ItemGroup> <ApprovedFiles Include="**\*.approved.txt" /> </ItemGroup> <Copy SourceFiles="@(ApprovedFiles)" DestinationFolder="$(OutputPath)\ApprovedFiles" /> </Target> </Project>
CodeCoverage.runsettings配置
<?xml version="1.0" encoding="utf-8" ?> <RunSettings> <DataCollectionRunSettings> <DataCollectors> <DataCollector friendlyName="XPlat Code Coverage"> <Configuration> <ExcludeByFile>**/*Test*/**/*.*</ExcludeByFile> </Configuration> </DataCollector> </DataCollectors> </DataCollectionRunSettings> </RunSettings>
内容的提问来源于stack exchange,提问作者rbasniak
相关产品推荐
相关产品推荐

