diff --git a/.gitignore b/.gitignore index 58cf11336..365c4bff0 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 e06d23e68..cff10c3ea 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 16a0851b8..e8c71e9f2 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 09fda2ffe..9ed29918d 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 3a985166a..1f85089ad 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 000000000..4c634d474 --- /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