coverlet icon indicating copy to clipboard operation
coverlet copied to clipboard

[BUG] coverlet.msbuild Support for Microsoft.Testing.Platform (not to be confused with VSTest Platform)

Open Arthri opened this issue 1 year ago • 8 comments

Describe the bug coverlet.msbuild does not work with the new testing platform server mode

To Reproduce Create a new unit tests project using TUnit. Add coverlet.msbuild as a dependency to the project. Run with the command dotnet test -p:CollectCoverage=true -p:CoverletOutputFormat=opencover

Expected behavior A code coverage report is generated somewhere, anywhere.

Actual behavior No code coverage report is generated.

Configuration (please complete the following information): Please provide more information on your .NET configuration: * Which coverlet package and version was used? coverlet.msbuild and 6.0.2 * Which version of .NET is the code running on? 9.0.100 * What OS and version, and what distro if applicable? Windows 10 22H2 * What is the architecture (x64, x86, ARM, ARM64)? x64 * Do you know whether it is specific to that configuration? Uncertain.

Additional context One of the two instrumentation targets, InstrumentModulesAfterBuild, depends on(runs after) the BuildProject target, which no longer exists under the new Microsoft Testing Platform. Therefore, instrumentation is not ran regardless of what happens.

I've found two solutions to the problem, but neither of which are extensively tested.

  1. Recreate BuildProject, so that the instrumentation target has something to hook onto and is able to run. Add a Directory.Build.targets in the same directory as the project, then set its contents to the following,
    <Project>
      <Target Name="BuildProject" BeforeTargets="InvokeTestingPlatform" />
    </Project>
    
    It doesn't matter that BuildProject is empty and does nothing, because the project build is handled by the _BuildAndInvokeTestingPlatform target.
  2. Pass the --no-build option to dotnet test, for example, dotnet test -p:CollectCoverage=true -p:CoverletOutputFormat=opencover --no-build. This solution depends on the other instrumentation target, InstrumentModulesNoBuild, which depends on(runs before) the VSTest target. The aforementioned target still exists on the new testing platform.

coverlet.console works, from prior testing.

Arthri avatar Dec 01 '24 09:12 Arthri

Thanks for reporting. Like @MarcoRossignoli already mentioned in the linked issue. We currently don't have support for Microsoft.Testing.Platform yet. But we already discussed adding the support and collected some strategies how to do that.

daveMueller avatar Jan 21 '25 23:01 daveMueller

I know it's early days -> would love to see some post on roadmap (for this item). E.g. planning to have something in the public at end of 2025. or .. we don't plan on doing this .. or we hope to get some planning done by Q1 2025, etc.

just so we have some expectations, etc.

PureKrome avatar Jan 21 '25 23:01 PureKrome

I can only speak for myself and I actually already planned this as one of the next topics. But I can't guarantee any ETA.

daveMueller avatar Jan 23 '25 21:01 daveMueller

@daveMueller Any update here?

Youssef1313 avatar May 30 '25 13:05 Youssef1313

I had a bit of discussion with @MarcoRossignoli on this. Coverlet should only support MTP via a platform extension, and not via MSBuild integration.

Youssef1313 avatar Jun 26 '25 13:06 Youssef1313

Looking forward to this. WOOT!

PureKrome avatar Jun 27 '25 04:06 PureKrome

+1. We (dotnet/runtime and other core stack repos) would love an MTP (Microsoft Test Platform) extension for coverlet so that we can instrument and measure code coverage with coverlet via dotnet test --coverage.

ViktorHofer avatar Jul 01 '25 11:07 ViktorHofer