From 4ada179ada53725fc9e8965a0a90bd2a9d115146 Mon Sep 17 00:00:00 2001 From: Justin Baur <136baur@gmail.com> Date: Thu, 20 May 2021 20:43:05 -0400 Subject: [PATCH] Implement Code Coverage --- .gitignore | 1 + dotnet-tools.json | 12 ++++++++++ test/Api.Test/Api.Test.csproj | 4 ++++ test/Core.Test/Core.Test.csproj | 4 ++++ test/Icons.Test/Icons.Test.csproj | 4 ++++ test/coverage.ps1 | 38 +++++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+) create mode 100644 test/coverage.ps1 diff --git a/.gitignore b/.gitignore index 58cf11336d..365c4bff06 100644 --- a/.gitignore +++ b/.gitignore @@ -214,3 +214,4 @@ bitwarden_license/src/Portal/wwwroot/css bitwarden_license/src/Sso/wwwroot/lib bitwarden_license/src/Sso/wwwroot/css .github/test/build.secrets +**/CoverageOutput/ diff --git a/dotnet-tools.json b/dotnet-tools.json index e06d23e68f..cff10c3eab 100644 --- a/dotnet-tools.json +++ b/dotnet-tools.json @@ -7,6 +7,18 @@ "commands": [ "swagger" ] + }, + "coverlet.console": { + "version": "3.0.3", + "commands": [ + "coverlet" + ] + }, + "dotnet-reportgenerator-globaltool": { + "version": "4.8.8", + "commands": [ + "reportgenerator" + ] } } } \ No newline at end of file diff --git a/test/Api.Test/Api.Test.csproj b/test/Api.Test/Api.Test.csproj index 16a0851b88..e8c71e9f23 100644 --- a/test/Api.Test/Api.Test.csproj +++ b/test/Api.Test/Api.Test.csproj @@ -5,6 +5,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/test/Core.Test/Core.Test.csproj b/test/Core.Test/Core.Test.csproj index 09fda2ffe1..9ed29918d5 100644 --- a/test/Core.Test/Core.Test.csproj +++ b/test/Core.Test/Core.Test.csproj @@ -6,6 +6,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/test/Icons.Test/Icons.Test.csproj b/test/Icons.Test/Icons.Test.csproj index 3a985166a1..1f85089ad8 100644 --- a/test/Icons.Test/Icons.Test.csproj +++ b/test/Icons.Test/Icons.Test.csproj @@ -5,6 +5,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/test/coverage.ps1 b/test/coverage.ps1 new file mode 100644 index 0000000000..4c634d4744 --- /dev/null +++ b/test/coverage.ps1 @@ -0,0 +1,38 @@ +param( + [string][Alias('c')]$configuration = "Release", + [string][Alias('o')]$output = "CoverageOutput" +) + +function Install-Tools { + dotnet tool install dotnet-reportgenerator-globaltool + dotnet tool install coverlet.console +} + +function Print-Environment { + dotnet --version + dotnet tool run coverlet --version +} + +function Prepare-Output { + if (Test-Path -Path $output) { + Remove-Item $output -Recurse + } +} + +function Run-Tests { + $testProjects = Get-ChildItem -Filter "*.Test.csproj" -Recurse + + foreach ($testProject in $testProjects) + { + dotnet test $testProject.FullName /p:CoverletOutputFormatter="cobertura" --collect:"XPlat Code Coverage" --results-directory:"$output" -c $configuration + } + + dotnet tool run reportgenerator -reports:$output/**/*.cobertura.xml -targetdir:$output -reporttypes:"Html;Cobertura" +} + +Write-Host "Collecting Code Coverage" + +Install-Tools +Print-Environment +Prepare-Output +Run-Tests