aspire icon indicating copy to clipboard operation
aspire copied to clipboard

Code coverage reporting using popular tools does not work with Aspire.Hosting.Testing

Open hwoodiwiss opened this issue 8 months ago • 2 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

When using Aspire.Hosting.Testing to run integration tests, and using coverlet.msbuild we had no coverage reported for our tests, regardless of what code they exercised. This reduces the value of the tests that otherwise provide a great amount of value by exercising our system front-to-back.

Describe the solution you'd like

It would be useful if coverage tooling that already exists would just work ™, however I appreciate that given how different running an application in Aspire/DistributedApplicationFactory is from something like WebApplicationFactory, that may be unworkable.

I think whatever the solution, it will require some collaboration with the maintainers of coverage tooling.

Additional context

No response

hwoodiwiss avatar Apr 02 '25 09:04 hwoodiwiss

cc @ReubenBond

radical avatar Apr 02 '25 17:04 radical

I've been going over the functionality that coverlet provides as-is and there seem to be opportunities for out of process coverage collection: dotnet-coverage in server mode.

Perhaps on the testing side of things Aspire could support a way to instead of build > run app > run tests to add some extra 'hooks' to build > instrument > run collector > run app > run tests > shutdown collector. It seems from the docs that we could just run these dotnet-coverage commands at the right time and get this working that way.

I am however unsure if that is a desirable implementation.

ArcadeMode avatar Apr 27 '25 07:04 ArcadeMode

Did you ever get to the bottom of this, I've just hit the same issue.

TheRubble avatar Jun 13 '25 07:06 TheRubble

@TheRubble I personally did not, but would love to see this resolved.

I'd guess that the intrumentation steps could still work as is, but the collector being the main problem due to the app running outside the aspire process (which is where the coverage collector is probably collecting from).

Will this issue get attention from the team sometime @radical / @ReubenBond? If a core contributor could point out a desired implementation that could be a starting point for contributions to be made.

I will also ask around in the coverlet repo to see if they have any suggestions

ArcadeMode avatar Jun 16 '25 09:06 ArcadeMode

I'm hitting this as well. I wouldn't mind contributing to fix the issue if we had a defined plan of the best way to accomplish this.

deanro avatar Jun 27 '25 22:06 deanro

I'm also getting the same problem, the weird thing is that using the FineCodeCoverage extension and running the tests via VisualStudio, code coverage gets reported correctly. It's only when running it via the console that it shows the code as being uncovered.

nuno-tiago-reis avatar Jul 04 '25 16:07 nuno-tiago-reis

Similarly I also need it to run from the command line. We have some some folks using Visual Studio on Windows, and some are using Rider on the Mac, we also have a GitHub workflow that builds all the code, runs all the tests and generates the code coverage report using reportgenerator, which is where this really needs to work. I tried assigning an issue to Copilot in our private repro and after about 7 attempts, it hopelessly failed to generate the code coverage for the services that are started via the apphost test - after using many of my credits 🙂

deanro avatar Jul 07 '25 15:07 deanro

https://github.com/coverlet-coverage/coverlet/issues/1760#issuecomment-3093678971

Sharing this reply in the coverlet repo. There's a suggested workaround with coverlet.console. Doesn't seem too hard to include in a simple script which runs dotnet test and sets up coverage collection.

ArcadeMode avatar Jul 22 '25 20:07 ArcadeMode