Microsoft.CodeCoverage.Console.exe don't use my runsettings correctly with Google Test

julian lalu 21 Reputation points
2022-09-29T12:20:35.627+00:00

Hello,

I have a full C++ code that is tested with Google test.
I generate a code coverage with VS 2022 with the Microsoft.CodeCoverage.Console.exe.
The converage works well but I don't manage how to use the runsettings file to filter namespace that I don't want.
In me case, I don't want to cover the testing namespace of Google Test.
Here is the command I launch to instrument and collect coverage:

Start-Process -FilePath "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Microsoft\CodeCoverage.Console\Microsoft.CodeCoverage.Console.exe" -ArgumentList "instrument .\target\test\Debug\test_core.exe -s .\target\test\code_coverage.runsettings" -NoNewWindow -Wait  
The input file has been instrumented.  
Start-Process -FilePath "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Microsoft\CodeCoverage.Console\Microsoft.CodeCoverage.Console.exe" -ArgumentList "collect .\target\test\Debug\test_core.exe -s .\target\test\code_coverage.runsettings -o .\target\test\Debug\coverage -f xml" -NoNewWindow -Wait  
Code coverage results : .\target\test\Debug\coverage.xml  

When I import the file in VS 2022 I see that it export everything:
246084-image.png

but I explicitly ask to not export testing in many ways in the code_coverage.runsettings:

<?xml version="1.0" encoding="utf-8"?>  
<!-- File name extension must be .runsettings -->  
<RunSettings>  
 <DataCollectionRunSettings>  
 <DataCollectors>  
 <DataCollector friendlyName="Code Coverage" uri="datacolsdsector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">  
 <Configuration>  
 <CodeCoverage>  
 <!-- Match fully qualified names of functions: -->  
 <!-- (Use "\." to delimit namespaces in C# or Visual Basic, "::" in C++.)  -->  
 <Functions>  
 <Exclude>  
 <Function>^std::.*</Function>  
 <Function>.*testing::.*</Function>  
 <Function>^testing::.*</Function>  
 <Function>.*testing.*</Function>  
 <Function>.*testing\..*</Function>  
 </Exclude>  
 </Functions>  
  
 <UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>  
 <AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>  
 <CollectFromChildProcesses>True</CollectFromChildProcesses>  
 <EnableStaticNativeInstrumentation>True</EnableStaticNativeInstrumentation>  
 <EnableDynamicNativeInstrumentation>False</EnableDynamicNativeInstrumentation>  
 <EnableStaticNativeInstrumentationRestore>True</EnableStaticNativeInstrumentationRestore>  
 </CodeCoverage>  
 </Configuration>  
 </DataCollector>  
 </DataCollectors>  
 </DataCollectionRunSettings>  
</RunSettings>  
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
328 questions
0 comments No comments
{count} votes

Accepted answer
  1. 77780164 76 Reputation points Microsoft Employee
    2022-10-10T09:29:47.253+00:00

    Please try to use config from here:
    https://learn.microsoft.com/en-us/dotnet/core/additional-tools/dotnet-coverage#settings

    FYI <RunSettings> tag should be used only for scenarios like vstest.console.exe or 'dotnet test'.
    For dotnet-coverage tool and Microsoft.CodeCoverage.Console you should use only inner part. Root should be <Configuration> tag.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. julian lalu 21 Reputation points
    2022-09-29T13:19:53.137+00:00

    I find that the path code_coverage.runsettings was not correct BUT!
    If the path is correct I have an error

    There is an error in the XML document (0, 0).

    0 comments No comments

  2. Tianyu Sun-MSFT 27,266 Reputation points Microsoft Vendor
    2022-09-30T07:40:50.37+00:00

    Hi @julian lalu ,

    Welcome to Microsoft Q&A forum.

    I see that there are some test characters beside <CodeCoverage>. This => <CodeCoverage> dsqdqsdsq. If they are just used for testing, have you deleted them?

    Besides, did you follow any guide or documents to use <Function>/<Functions> property? If you remove or comment the <Functions> block, will the .runsettings file pass to run and will the error disappear?

    Best Regards,
    Tianyu

    • If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.