Open glektarssza opened 2 days ago
Tagging @fhnaseer to help.
@glektarssza As you mentioned, LibraryImport.g.cs is added because you are using System.Runtime.InteropServices.LibraryImport
. We do not exclude .g.cs files by default. Some people want to have coverage for this. You can exclude auto-generated files by adding the following snippet in the runsettings file.
<Sources>
<Exclude>
<Source>.*\.g\.cs$</Source>
</Exclude>
</Sources>
Will test and report back.
Side note, apparently the setting dotnet.unitTests.runSettingsPath
does not respect VSCode variables.
Setting it to:
"dotnet.unitTests.runSettingsPath": "${workspaceFolder}/coverage.runsettings"
produced the following error:
Cannot read runsettings file at: c:\Users\GlekLaptop\repositories\github\glektarssza\glekcraft\${workspaceFolder}\coverage.runsettings
When I set it to a custom runsettings
file, though, I get absolutely spammed with coverage values from the dotnet
SDK...
Or at least I assume these are from the dotnet
SDK. They might be from the MSTest framework? I'm not sure but that seems more likely.
If no runsettings are provided then we exclude a lot of stuff from the coverage report. When you use a custom runsettings file, then these are not excluded. By looking at your report, I would suggest to add the following in your runsettings file.
<!-- Match the path of the source files in which each method is defined: -->
<Sources>
<Exclude>
<Source>.*\\atlmfc\\.*</Source>
<Source>.*\\vctools\\.*</Source>
<Source>.*\\public\\sdk\\.*</Source>
<Source>.*\\microsoft sdks\\.*</Source>
<Source>.*\\vc\\include\\.*</Source>
</Exclude>
</Sources>
<!-- Match the company name property in the assembly: -->
<CompanyNames>
<Exclude>
<CompanyName>.*microsoft.*</CompanyName>
</Exclude>
</CompanyNames>
Side note, apparently the setting
dotnet.unitTests.runSettingsPath
does not respect VSCode variables.Setting it to:
"dotnet.unitTests.runSettingsPath": "${workspaceFolder}/coverage.runsettings"
produced the following error:
Cannot read runsettings file at: c:\Users\GlekLaptop\repositories\github\glektarssza\glekcraft\${workspaceFolder}\coverage.runsettings
@AbhitejJohn can you create a bug for this and assign it to someone?
If no runsettings are provided then we exclude a lot of stuff from the coverage report. When you use a custom runsettings file, then these are not excluded. By looking at your report, I would suggest to add the following in your runsettings file. [SNIPPED]
This has worked, with a bit more added to remove other dependencies I've included in my project. Not exactly intuitive but it has worked. Thanks for the assistance.
Describe the Issue
Running unit tests inside VSCode with coverage enabled generates coverage metrics for files that are automatically generated by the
dotnet
SDK and placed inside of theobj
folder. For example,LibraryImports.g.cs
which is created when using theSystem.Runtime.InteropServices.LibraryImport
attribute to access native code.As this file does not technically exist on disk it leads to strange behavior (0% coverage, errors when trying to open the file to view, etc.)
See the below screenshot for an example of this issue in action.
Screenshot is from this repository and commit.
Steps To Reproduce
Expected Behavior
Code coverage is not reported for
LibraryImports.g.cs
or any other files inside of theobj
orbin
folders.Environment Information
ms-dotnettools.csharp
Version: v2.46.32 (pre-release)