首页 > 解决方案 > dotnet 测试无法找到友好名称“代码覆盖率”的数据收集器

问题描述

几个月前,当我们的项目还在 .NET 4.7.2 中时,我们曾经使用该Visual Studio Test任务在 Azure DevOps Server 上运行单元测试。我们使用参数Test files来指定哪些测试程序集需要运行并且Code Coverage在那里工作得很好。

由于我们将项目迁移到 .NET 5.0,我们使用dotnet test运行单元测试,现在Code Coverage不再工作。

这是一个例子:

D:\test-2-1\_tool\dotnet\dotnet.exe test A.Test.dll B.Test.dll C.Test.dll --logger trx --results-directory D:\test-2-1\_temp --settings D:\test-2-1\5\s\.runsettings
Microsoft (R) Test Execution Command Line Tool Version 16.9.4
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 22 test files matched the specified pattern.
Data collection : Unable to find a datacollector with friendly name 'Code Coverage'.
Data collection : Could not find data collector 'Code Coverage'

内容.runsettings

<DataCollectionRunSettings>
    <DataCollectors>
        <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
            <Configuration>
                <CodeCoverage>
                    <ModulePaths>
                        <Include>
                            <ModulePath>{someRegexToLimitCodeCoverageToSpecificTestAssemblies}</ModulePath>
                        </Include>
                    </ModulePaths>
                </CodeCoverage>
            </Configuration>
        </DataCollector>
    </DataCollectors>
</DataCollectionRunSettings>

在另一个较小的项目中,Code Coverage仍然可以工作,但在这里我们指定应该测试哪些项目文件,而不是哪些编译的测试程序集

这是现在要走的路吗?如果是,是否有可能通过指定测试程序集让它恢复工作?

提前致谢!

标签: .netxmlunit-testingcode-coveragemstest

解决方案


推荐阅读