A few months ago, when our projects were still in .NET 4.7.2, we used to run unit tests on our Azure DevOps Server using the Visual Studio Test
task. We used parameter Test files
to specify which test assemblies need to run and Code Coverage
worked just fine there.
Since we migrated our projects to .NET 5.0, we use dotnet test
to run unit tests and now Code Coverage
doesn't work anymore.
Here's an example:
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'
Content of .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>
In another smaller project, Code Coverage
still works, but here we specify which project files should be tested, rather than which compiled test assemblies.
Is this the way to go now and if yes, is it possible to get it back to work with specifying test assemblies too?
Thanks in advance!
@LoriB
The problem in my Azure Devops pipeline was that the developer used the built dll's as the project argument for testing. This worked for running the unit tests, but not for the code coverage. Instead of using **/*Tests.dll
as an argument
I now changed it to **/*Tests.csproj
and now the code coverage works.
In the example of the question, the line
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
should be changed to (change .dll
extension to .csproj
)
D:\test-2-1\_tool\dotnet\dotnet.exe test A.Test.csproj B.Test.csproj C.Test.csproj --logger trx --results-directory D:\test-2-1\_temp --settings D:\test-2-1\5\s\.runsettings
or even better
D:\test-2-1\_tool\dotnet\dotnet.exe test **/*.Test.csproj --logger trx --results-directory D:\test-2-1\_temp --settings D:\test-2-1\5\s\.runsettings
EDIT:
But to answer your question:
This is what the help of dotnet.exe says:
Usage: dotnet test [options] <PROJECT | SOLUTION> [[--] ...]]
Arguments: <PROJECT | SOLUTION> The project or solution file to operate on. If a file is not specified, the command will search the current directory for one.
Although I found examples with dll's, dotnet.exe asks for a project or solution file. And not a library or any other assembly. And since I couldn't get code coverage to work with the dll's I suggest not to use assemblies as input. Only project or solution files.