BryanWilhite / SonghayCore

core reusable, opinionated concerns for *all* 🧐 of my C# projects
http://songhayblog.azurewebsites.net/
MIT License
1 stars 0 forks source link

add coverlet test coverage reporting #140

Closed BryanWilhite closed 2 years ago

BryanWilhite commented 2 years ago

📖 https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-code-coverage?tabs=linux

This command from Microsoft is showing me what I am missing—the --collect argument:

dotnet test --collect:"XPlat Code Coverage"

It can be applied among my tasks:

{
    "label": "dotnet test [SonghayCore.Tests]",
    "command": "dotnet",
    "type": "shell",
    "args": [
        "test",
        "${workspaceFolder}/SonghayCore.Tests/SonghayCore.Tests.csproj",
        "--logger:trx",
        "--results-directory:${workspaceFolder}/TestResults",
        "--verbosity:normal",
        "--collect:\"XPlat Code Coverage\""
    ],
    "problemMatcher": "$msCompile"
},
BryanWilhite commented 2 years ago

For the HTML reporting, we install ReportGenerator [GitHub]:

dotnet tool install -g dotnet-reportgenerator-globaltool

🐚↓

$ dotnet tool install -g dotnet-reportgenerator-globaltool
You can invoke the tool using the following command: reportgenerator
Tool 'dotnet-reportgenerator-globaltool' (version '5.1.9') was successfully installed.

The reportgenerator VSCode task looks like this:

{
    "label": "reportgenerator [SonghayCore.Tests]",
    "command": "reportgenerator",
    "type": "shell",
    "args": [
        "-reports:\"${workspaceFolder}/TestResults/*/coverage.cobertura.xml\"",
        "-reporttypes:Html",
        "-targetdir:\"${workspaceFolder}/docs/coverlet\"",
        "-title:SonghayCore"
    ],
    "problemMatcher": []
},

image