From 902d3070bc216ac0ebb6ed15a2046e617e074e4f Mon Sep 17 00:00:00 2001 From: Mike Minns Date: Mon, 18 Oct 2021 15:36:08 +0100 Subject: [PATCH] Basic support for generating code coverage reports TODO include in GitHub actions etc setup, e.g. https://josh-ops.com/posts/github-code-coverage/, once https://github.com/microsoft/vstest/issues/1811 is fixed --- .code-coverage/coverlet.settings.xml | 12 +++++ .vscode/tasks.json | 50 ++++++++++++++++++- docs/development.md | 37 ++++++++++++++ .../Atlassian.Bitbucket.Tests.csproj | 5 ++ src/shared/GitHub.Tests/GitHub.Tests.csproj | 5 ++ .../Microsoft.AzureRepos.Tests.csproj | 5 ++ ...crosoft.Git.CredentialManager.Tests.csproj | 5 ++ .../TestInfrastructure.csproj | 1 + 8 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 .code-coverage/coverlet.settings.xml diff --git a/.code-coverage/coverlet.settings.xml b/.code-coverage/coverlet.settings.xml new file mode 100644 index 000000000..ec81f0fa9 --- /dev/null +++ b/.code-coverage/coverlet.settings.xml @@ -0,0 +1,12 @@ + + + + + + + cobertura,lcov + + + + + \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7d01b676b..76c04656e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -31,6 +31,54 @@ "reveal": "always", "panel": "dedicated" } + }, + { + "label": "test with coverage", + "command": "dotnet", + "type": "shell", + "group": "test", + "args": [ + "test", + "${workspaceFolder}/Git-Credential-Manager.sln", + "--collect", + "'XPlat Code Coverage'", + "--settings", + "${workspaceFolder}/.code-coverage/coverlet.settings.xml" + ], + "presentation": { + "reveal": "always", + "panel": "dedicated" + } + }, + { + "label": "report coverage - nix", + "command": "dotnet", + "type": "shell", + "group": "test", + "args": [ + "~/.nuget/packages/reportgenerator/*/*/net5.0/ReportGenerator.dll", + "-reports:${workspaceFolder}/**/TestResults/**/coverage.cobertura.xml", + "-targetdir:${workspaceFolder}/out/code-coverage" + ], + "presentation": { + "reveal": "always", + "panel": "dedicated" + } + }, + { + "label": "report coverage - win", + "command": "dotnet", + "type": "shell", + "group": "test", + "args": [ + "${env:USERROFILE}/.nuget/packages/reportgenerator/*/*/net5.0/ReportGenerator.dll", + "-reports:${workspaceFolder}/**/TestResults/**/coverage.cobertura.xml", + "-targetdir:${workspaceFolder}/out/code-coverage" + ], + "presentation": { + "reveal": "always", + "panel": "dedicated" + } } ] -} +} \ No newline at end of file diff --git a/docs/development.md b/docs/development.md index 20c19551b..1e9c9c136 100644 --- a/docs/development.md +++ b/docs/development.md @@ -95,3 +95,40 @@ $ GCM_TRACE=1 git-credential-manager-core version > 18:47:56.526712 ...er/Application.cs:69 trace: [RunInternalAsync] Git Credential Manager version 2.0.124-beta+e1ebbe1517 (macOS, .NET 5.0) 'version' > Git Credential Manager version 2.0.124-beta+e1ebbe1517 (macOS, .NET 5.0) ``` + +### Code coverage metrics + +If you want code coverage metrics these can be generated either from the command line: + +```shell +$ dotnet test --collect:"XPlat Code Coverage" --settings=./.code-coverage/coverlet.settings.xml +``` + +Or via the VSCode Terminal/Run Task: + +``` +test with coverage +``` + +HTML reports can be generated using ReportGenerator, this should be installed during the build process, from the command line: + +```shell +$ dotnet ~/.nuget/packages/reportgenerator/*/*/net5.0/ReportGenerator.dll -reports:./**/TestResults/**/coverage.cobertura.xml -targetdir:./out/code-coverage +``` +or + +```shell +$ dotnet {$env:USERPROFILE}/.nuget/packages/reportgenerator/*/*/net5.0/ReportGenerator.dll -reports:./**/TestResults/**/coverage.cobertura.xml -targetdir:./out/code-coverage +``` + +Or via VSCode Terminal/Run Task: + +``` +report coverage - nix +``` + +or + +``` +report coverage - win +``` \ No newline at end of file diff --git a/src/shared/Atlassian.Bitbucket.Tests/Atlassian.Bitbucket.Tests.csproj b/src/shared/Atlassian.Bitbucket.Tests/Atlassian.Bitbucket.Tests.csproj index c7d3c76a6..a8597e4fc 100644 --- a/src/shared/Atlassian.Bitbucket.Tests/Atlassian.Bitbucket.Tests.csproj +++ b/src/shared/Atlassian.Bitbucket.Tests/Atlassian.Bitbucket.Tests.csproj @@ -8,7 +8,12 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + diff --git a/src/shared/GitHub.Tests/GitHub.Tests.csproj b/src/shared/GitHub.Tests/GitHub.Tests.csproj index 05f016299..cff5ce92c 100644 --- a/src/shared/GitHub.Tests/GitHub.Tests.csproj +++ b/src/shared/GitHub.Tests/GitHub.Tests.csproj @@ -8,7 +8,12 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + diff --git a/src/shared/Microsoft.AzureRepos.Tests/Microsoft.AzureRepos.Tests.csproj b/src/shared/Microsoft.AzureRepos.Tests/Microsoft.AzureRepos.Tests.csproj index 0b5ecb20a..e1872e6e9 100644 --- a/src/shared/Microsoft.AzureRepos.Tests/Microsoft.AzureRepos.Tests.csproj +++ b/src/shared/Microsoft.AzureRepos.Tests/Microsoft.AzureRepos.Tests.csproj @@ -8,7 +8,12 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + diff --git a/src/shared/Microsoft.Git.CredentialManager.Tests/Microsoft.Git.CredentialManager.Tests.csproj b/src/shared/Microsoft.Git.CredentialManager.Tests/Microsoft.Git.CredentialManager.Tests.csproj index b264d2312..4c704abc8 100644 --- a/src/shared/Microsoft.Git.CredentialManager.Tests/Microsoft.Git.CredentialManager.Tests.csproj +++ b/src/shared/Microsoft.Git.CredentialManager.Tests/Microsoft.Git.CredentialManager.Tests.csproj @@ -9,7 +9,12 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + diff --git a/src/shared/TestInfrastructure/TestInfrastructure.csproj b/src/shared/TestInfrastructure/TestInfrastructure.csproj index fcf2af69e..858806193 100644 --- a/src/shared/TestInfrastructure/TestInfrastructure.csproj +++ b/src/shared/TestInfrastructure/TestInfrastructure.csproj @@ -10,6 +10,7 @@ +