mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
Implement code coverage tool (#1390)
* Implement code coverage tool * Switch to solution style of running tests * Add shell version of coverage file * Fix formatting in coverage.sh * Add trailing newline to powershell
This commit is contained in:
parent
658f79b80e
commit
59268790c9
1
.gitignore
vendored
1
.gitignore
vendored
@ -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/
|
||||
|
@ -7,6 +7,18 @@
|
||||
"commands": [
|
||||
"swagger"
|
||||
]
|
||||
},
|
||||
"coverlet.console": {
|
||||
"version": "3.0.3",
|
||||
"commands": [
|
||||
"coverlet"
|
||||
]
|
||||
},
|
||||
"dotnet-reportgenerator-globaltool": {
|
||||
"version": "4.8.8",
|
||||
"commands": [
|
||||
"reportgenerator"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||
<PackageReference Include="NSubstitute" Version="4.2.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
|
@ -6,6 +6,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||
<PackageReference Include="NSubstitute" Version="4.2.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
|
@ -5,6 +5,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||
<PackageReference Include="NSubstitute" Version="4.2.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
|
62
test/bitwarden.tests.sln
Normal file
62
test/bitwarden.tests.sln
Normal file
@ -0,0 +1,62 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30114.105
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Test", "Core.Test\Core.Test.csproj", "{A871C001-E815-4044-846E-06B30E110B79}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Icons.Test", "Icons.Test\Icons.Test.csproj", "{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api.Test", "Api.Test\Api.Test.csproj", "{2B29139A-E3B5-4A44-8A85-1593ACB797CC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A871C001-E815-4044-846E-06B30E110B79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A871C001-E815-4044-846E-06B30E110B79}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A871C001-E815-4044-846E-06B30E110B79}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{A871C001-E815-4044-846E-06B30E110B79}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{A871C001-E815-4044-846E-06B30E110B79}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{A871C001-E815-4044-846E-06B30E110B79}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{A871C001-E815-4044-846E-06B30E110B79}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A871C001-E815-4044-846E-06B30E110B79}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A871C001-E815-4044-846E-06B30E110B79}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{A871C001-E815-4044-846E-06B30E110B79}.Release|x64.Build.0 = Release|Any CPU
|
||||
{A871C001-E815-4044-846E-06B30E110B79}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{A871C001-E815-4044-846E-06B30E110B79}.Release|x86.Build.0 = Release|Any CPU
|
||||
{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}.Release|x64.Build.0 = Release|Any CPU
|
||||
{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{5B4A482F-1EA1-40A7-89DA-21BE6B897FA6}.Release|x86.Build.0 = Release|Any CPU
|
||||
{2B29139A-E3B5-4A44-8A85-1593ACB797CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2B29139A-E3B5-4A44-8A85-1593ACB797CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2B29139A-E3B5-4A44-8A85-1593ACB797CC}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{2B29139A-E3B5-4A44-8A85-1593ACB797CC}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{2B29139A-E3B5-4A44-8A85-1593ACB797CC}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{2B29139A-E3B5-4A44-8A85-1593ACB797CC}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{2B29139A-E3B5-4A44-8A85-1593ACB797CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2B29139A-E3B5-4A44-8A85-1593ACB797CC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2B29139A-E3B5-4A44-8A85-1593ACB797CC}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{2B29139A-E3B5-4A44-8A85-1593ACB797CC}.Release|x64.Build.0 = Release|Any CPU
|
||||
{2B29139A-E3B5-4A44-8A85-1593ACB797CC}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{2B29139A-E3B5-4A44-8A85-1593ACB797CC}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
31
test/coverage.ps1
Normal file
31
test/coverage.ps1
Normal file
@ -0,0 +1,31 @@
|
||||
param(
|
||||
[string][Alias('c')]$Configuration = "Release",
|
||||
[string][Alias('o')]$Output = "CoverageOutput",
|
||||
[string][Alias('rt')]$ReportType = "lcov"
|
||||
)
|
||||
|
||||
function Install-Tools {
|
||||
dotnet tool restore
|
||||
}
|
||||
|
||||
function Print-Environment {
|
||||
dotnet --version
|
||||
}
|
||||
|
||||
function Prepare-Output {
|
||||
if (Test-Path -Path $Output) {
|
||||
Remove-Item $Output -Recurse
|
||||
}
|
||||
}
|
||||
|
||||
function Run-Tests {
|
||||
dotnet test $PSScriptRoot/bitwarden.tests.sln /p:CoverletOutputFormatter="cobertura" --collect:"XPlat Code Coverage" --results-directory:"$Output" -c $Configuration
|
||||
|
||||
dotnet tool run reportgenerator -reports:$Output/**/*.cobertura.xml -targetdir:$Output -reporttypes:"$ReportType"
|
||||
}
|
||||
|
||||
Write-Host "Collecting Code Coverage"
|
||||
Install-Tools
|
||||
Print-Environment
|
||||
Prepare-Output
|
||||
Run-Tests
|
53
test/coverage.sh
Normal file
53
test/coverage.sh
Normal file
@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set defaults if no values supplied
|
||||
CONFIGURATION="Release"
|
||||
OUTPUT="CoverageOutput"
|
||||
REPORT_TYPE="lcov"
|
||||
|
||||
|
||||
# Read in arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
|
||||
case $key in
|
||||
-c|--configuration)
|
||||
|
||||
CONFIGURATION="$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-o|--output)
|
||||
OUTPUT="$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-rt|--reportType)
|
||||
REPORT_TYPE="$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "CONFIGURATION = ${CONFIGURATION}"
|
||||
echo "OUTPUT = ${OUTPUT}"
|
||||
echo "REPORT_TYPE = ${REPORT_TYPE}"
|
||||
|
||||
echo "Collectiong Code Coverage"
|
||||
# Install tools
|
||||
dotnet tool restore
|
||||
# Print Environment
|
||||
dotnet --version
|
||||
|
||||
if [[ -d $OUTPUT ]]; then
|
||||
echo "Cleaning output location"
|
||||
rm -rf $OUTPUT
|
||||
fi
|
||||
|
||||
dotnet test "./bitwarden.tests.sln" /p:CoverletOutputFormatter="cobertura" --collect:"XPlat Code Coverage" --results-directory:"$OUTPUT" -c $CONFIGURATION
|
||||
|
||||
dotnet tool run reportgenerator -reports:$OUTPUT/**/*.cobertura.xml -targetdir:$OUTPUT -reporttype:"$REPORT_TYPE"
|
Loading…
Reference in New Issue
Block a user