Skip to content

Conversation

eberthold
Copy link
Contributor

Add support for coverage info in C# files using the dotnet command line.

It's not working out of the box because of the way dotnet test writes the coverage results. I for myself added a test execution script to my PATH which must be run from the project root, and writes the result in a way that the coverage could be collected with the nvim-coverage extension.

Therefore I would recommend adding a wiki page with language specific hints which would contain something like this:


The dotnet test tool per default writes one coverage result per test project. In addition to that the output is not deterministic and contains a subfolder with GUID per test run which are not deleted when another test run is started.
To tackle this a script like the following is recommended to collect all coverage results in a solution and merge it to a single results file, which then can be picked up by the coverage extension.

The ReportGenerator dotnet tool is used for merging reports

The script is written in powershell core which should work cross platform or can be easily translated to a bash script:

$projectTestResultName = "coverage.cobertura.xml"

# delete all previous test result of each test project to have correct report generator input
Get-ChildItem -include $projectTestResultName -recurse | ForEach-Object { Remove-Item $_.Directory -recurse }

# run tests
dotnet test --collect:"XPlat Code Coverage"

# merge reports
reportgenerator -reports:**/TestResults/*/$projectTestResultName -reporttypes:lcov -targetdir:TestResults

@andythigpen
Copy link
Owner

Thank you for the PR. I added your text verbatim to the wiki here https://github.com/andythigpen/nvim-coverage/wiki/C%23-support

@andythigpen andythigpen merged commit 7018f6d into andythigpen:main May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants