Vstest.console.exe creates cover art only for the Moq.dll file

I am trying to generate a code coverage report using vstest.console.exe . I also use the .runsettings file and pass it as a parameter.

No matter what I try to do, it generates a coverage report only for moq.dll.

I use below the full text of the command parameters that I run, as well as the contents of the .runsettings file. Any idea where I am doing something wrong?

Command:

vstest.console.exe "C: \ Xyz.Tests \ bin \ Debug \ netcoreapp2.0 \ Xyz.Tests.dll" / InIsolation /EnableCodeCoverage/settings:CodeCoverage.runsettings

Content Contents of CodeCoverage.runsettings :

<RunSettings> <DataCollectionRunSettings> <DataCollectors> <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" enabled="false"> <Configuration> <CodeCoverage> </CodeCoverage> </Configuration> </DataCollector> </DataCollectors> </DataCollectionRunSettings> </RunSettings> 

Image of generated code coverage report: enter image description here

+5
source share
1 answer

I came across the same behavior, but fortunately I found a solution:

Open the Visual Studio testing task and:

Uncheck Code coverage enabled Place --collect:"Code Coverage" in other console options

Edit the .csproj project file containing the tested classes, and:

Add <DebugType>full</DebugType> to the <PropertyGroup>

To avoid the appearance of moq.dll in the code coverage results:

Add <ModulePath>.*moq.dll</ModulePath> to the <ModulePaths> -> <Exclude> section of the .runsettings file

Here are my settings .runsettings

 <?xml version="1.0" encoding="utf-8"?> <RunSettings> <RunConfiguration> <MaxCpuCount>0</MaxCpuCount> </RunConfiguration> <DataCollectionRunSettings> <DataCollectors> <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <Configuration> <CodeCoverage> <!-- Match assembly file paths: --> <ModulePaths> <Include> <ModulePath>.*\.dll$</ModulePath> <ModulePath>.*\.exe$</ModulePath> </Include> <Exclude> <ModulePath>.*moq.dll</ModulePath> <ModulePath>.*CPPUnitTestFramework.*</ModulePath> <ModulePath>.*TestAdapter.*</ModulePath> </Exclude> </ModulePaths> </CodeCoverage> </Configuration> </DataCollector> </DataCollectors> </DataCollectionRunSettings> </RunSettings> 

And please check https://developercommunity.visualstudio.com/content/problem/92905/net-core-unit-testing-code-coverage.html link

0
source

Source: https://habr.com/ru/post/1275195/


All Articles