Skip to content

Commit

Permalink
Basic support for generating code coverage reports
Browse files Browse the repository at this point in the history
TODO include in GitHub actions etc setup, e.g. https://josh-ops.com/posts/github-code-coverage/, once microsoft/vstest#1811 is fixed
  • Loading branch information
mminns committed Oct 18, 2021
1 parent 53ea286 commit 902d307
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .code-coverage/coverlet.settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>cobertura,lcov</Format>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
50 changes: 49 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
}
}
37 changes: 37 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="ReportGenerator" Version="4.8.13" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/shared/GitHub.Tests/GitHub.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="ReportGenerator" Version="4.8.13" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="ReportGenerator" Version="4.8.13" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="ReportGenerator" Version="4.8.13" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/shared/TestInfrastructure/TestInfrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="ReportGenerator" Version="4.8.13" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
</ItemGroup>
Expand Down

0 comments on commit 902d307

Please sign in to comment.