Skip to content

[BUG] coverlet.console with vstest.console.exe reporting 0% coverage #1737

Open
@DavidTynewyddBI

Description

@DavidTynewyddBI

Describe the bug
I'm attempting to get code coverage on a WinUI3 project which includes tests marked with [UITestMethod].

If I ignore the UITestMethods, I can successfully get coverage using dotnet test --collect:"XPlat Code Coverage", however dotnet test doesn't work with UITestMethod, hence using vstest.console.exe.

I'm using coverlet.console, which runs the tests and reports the correct referenced projects but with 0% coverage, along with the message "Hits file not found for module ".

To Reproduce

  1. Create an empty winui3 class library with some public classes and methods
  2. Add a winui3 test project
  3. Reference the class library and call some but not all of the methods
  4. Build
  5. Run coverlet .\bin\x64\Debug\net8.0-windows10.0.19041.0\win-x64\TestApp1.build.appxrecipe --target "vstest.console.exe" --targetargs "bin\x64\Debug\net8.0-windows10.0.19041.0\win-x64\TestApp1.build.appxrecipe /Logger:trx" --verbosity detailed where TestApp1 is the name of your test project

Expected behavior
Tests to run and code coverage to be produced

Actual behavior
Either reports 0% or 100% while saying the hits file was not found.
e.g.

Terminating app with process ID '2144'.
  Passed TestMethod1 [5 ms]
  Passed TestMethod2 [12 ms]
  Passed TestMethod3 [28 ms]
Results File: <redacted>
Test Run Successful.
Total tests: 3
     Passed: 3
 Total time: 9.4086 Seconds

Calculating coverage result...
Hits file:'<redacted>\AppData\Local\Temp\ClassLibrary1_4dd00cc7-1a92-4f0b-a9ad-b917071ea6ab' not found for module: 'ClassLibrary1'
Hits file:'<redacted>\AppData\Local\Temp\TestApp1_4dd00cc7-1a92-4f0b-a9ad-b917071ea6ab' not found for module: 'TestApp1'
  Generating report '<redacted>\App1\TestApp1\coverage.json'
+---------------+------+--------+--------+
| Module        | Line | Branch | Method |
+---------------+------+--------+--------+
| ClassLibrary1 | 0%   | 100%   | 0%     |
+---------------+------+--------+--------+
| TestApp1      | 0%   | 0%     | 0%     |
+---------------+------+--------+--------+

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 0%   | 0%     | 0%     |
+---------+------+--------+--------+
| Average | 0%   | 50%    | 0%     |
+---------+------+--------+--------+

Configuration (please complete the following information):
Please provide more information on your .NET configuration:
* Which coverlet package and version was used? coverlet.console 6.0.4.1+90b21079d4
* Which version of .NET is the code running on? .net8
* What OS and version, and what distro if applicable? Windows 11 26100
* What is the architecture (x64, x86, ARM, ARM64)? x64
* Do you know whether it is specific to that configuration? Unknown

Additional context
I'm aware of the known issue giving 0% coverage, however this is an empty project with essentially empty tests.

❗ Please also read Known Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionThis issue is a questionuntriagedTo be investigatedwith reproIssue with repro

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions