Skip to content

Commit 9c12fb1

Browse files
authored
Create code coverage reports (#657)
* Run dotCover as part of running tests in build scripts * Upload reports to codecov.io * AppVeyor: Add commented config for enabling remote desktop * Add init scripts to download tooling * Upgrade all nugets * Make test.bat reuse build-functions.psm1 * Move secure envvar to AppVeyor UI, to work with PRs.
1 parent 8ee2d26 commit 9c12fb1

File tree

15 files changed

+103
-55
lines changed

15 files changed

+103
-55
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,6 @@ Artifacts
258258

259259
# Build server tooling
260260
/secure-file
261+
/Tools/reportgenerator.exe
262+
/Tools/.store/
263+
codecov.sh

Build/Test.ps1

Lines changed: 0 additions & 17 deletions
This file was deleted.

Build/build-functions.psm1

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
$artifactsDir = "$root\Artifacts"
33
$nugetOutDir = "$root\Artifacts\NuGet"
44
$testReportDir = "$root\Artifacts\Logs"
5+
$testCoverageDir = "$root\Artifacts\Coverage"
56
$nuget = "$root\Tools\NuGet.exe"
67
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
78
$msbuild = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
@@ -58,29 +59,38 @@ function Start-Build([boolean] $IncludeWindowsRuntimeComponent = $false) {
5859

5960
function Start-Tests {
6061
$projectPaths = @(
61-
"UnitsNet.Tests\UnitsNet.Tests.NetCore.csproj",
62-
"UnitsNet.Serialization.JsonNet.Tests\UnitsNet.Serialization.JsonNet.Tests.NetCore.csproj",
63-
"UnitsNet.Serialization.JsonNet.CompatibilityTests\UnitsNet.Serialization.JsonNet.CompatibilityTests.NetCore.csproj"
62+
"UnitsNet.Tests\UnitsNet.Tests.csproj",
63+
"UnitsNet.Serialization.JsonNet.Tests\UnitsNet.Serialization.JsonNet.Tests.csproj",
64+
"UnitsNet.Serialization.JsonNet.CompatibilityTests\UnitsNet.Serialization.JsonNet.CompatibilityTests.csproj"
6465
)
6566

6667
# Parent dir must exist before xunit tries to write files to it
6768
new-item -type directory -force $testReportDir 1> $null
69+
new-item -type directory -force $testCoverageDir 1> $null
6870

6971
write-host -foreground blue "Run tests...`n---"
7072
foreach ($projectPath in $projectPaths) {
7173
$projectFileNameNoEx = [System.IO.Path]::GetFileNameWithoutExtension($projectPath)
7274
$reportFile = "$testReportDir\${projectFileNameNoEx}.xunit.xml"
75+
$coverageReportFile = "$testCoverageDir\${projectFileNameNoEx}.coverage.xml"
7376
$projectDir = [System.IO.Path]::GetDirectoryName($projectPath)
7477

75-
# dotnet-xunit command must run in same dir as project
76-
# https://github.com/xunit/xunit/issues/1216
78+
# dotnet commands (xunit, dotcover) must run in same dir as project
7779
push-location $projectDir
78-
# -nobuild <-- this gives an error, but might want to use this to avoid extra builds
79-
dotnet xunit -configuration Release -framework netcoreapp2.0 -xml $reportFile -nobuild
80+
81+
# Create coverage report for this test project
82+
& dotnet dotcover test `
83+
--dotCoverFilters="+:module=UnitsNet*;-:module=*Tests" `
84+
--dotCoverOutput="$coverageReportFile" `
85+
--dcReportType=DetailedXML
86+
8087
if ($lastexitcode -ne 0) { exit 1 }
8188
pop-location
8289
}
8390

91+
# Generate a summarized code coverage report for all test projects
92+
& "Tools/reportgenerator.exe" -reports:"$root/Artifacts/Coverage/*.coverage.xml" -targetdir:"$root/Artifacts/Coverage" -reporttypes:HtmlSummary
93+
8494
write-host -foreground blue "Run tests...END`n"
8595
}
8696

Build/build.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ remove-module build-functions -ErrorAction SilentlyContinue
2727
import-module $PSScriptRoot\build-functions.psm1
2828

2929
try {
30+
& "$PSScriptRoot/init.ps1" # Ensure tools are downloaded
31+
3032
Remove-ArtifactsDir
3133
Update-GeneratedCode
3234
Start-Build -IncludeWindowsRuntimeComponent $IncludeWindowsRuntimeComponent

Build/init.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Don't allow using undeclared variables
2+
Set-Strictmode -version latest
3+
4+
$root = "$PSScriptRoot\.."
5+
Write-Host -Foreground Blue "Initializing..."
6+
7+
# Ensure temp dir exists
8+
$tempDir = "$root/Tools/Temp"
9+
[system.io.Directory]::CreateDirectory($tempDir) | out-null
10+
11+
if (-not (Test-Path "$root/Tools/reportgenerator.exe")) {
12+
Write-Host -Foreground Blue "Download dotnet-reportgenerator-globaltool..."
13+
dotnet tool install dotnet-reportgenerator-globaltool --tool-path Tools
14+
Write-Host -Foreground Green "Download dotnet-reportgenerator-globaltool...OK."
15+
}
16+
17+
# Cleanup
18+
[system.io.Directory]::Delete($tempDir, $true) | out-null
19+
20+
Write-Host -Foreground Green "Initialized."

CodeGen/CodeGen.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
9+
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
1010
<PackageReference Include="Serilog" Version="2.8.0" />
1111
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
1212
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.2.0-alpha.19174.3" />

UnitsNet.Benchmark/UnitsNet.Benchmark.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="BenchmarkDotNet" Version="0.11.4" />
18-
<PackageReference Include="CommandLineParser" Version="2.4.3" />
19-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.6.1">
17+
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
18+
<PackageReference Include="CommandLineParser" Version="2.5.0" />
19+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.9.3">
2020
<PrivateAssets>all</PrivateAssets>
2121
</PackageReference>
2222
</ItemGroup>

UnitsNet.Serialization.JsonNet.CompatibilityTests/UnitsNet.Serialization.JsonNet.CompatibilityTests.csproj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<RootNamespace>UnitsNet.Serialization.JsonNet.CompatibilityTests</RootNamespace>
66
<LangVersion>7.3</LangVersion>
77
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
8+
<IsTestProject>true</IsTestProject>
89
</PropertyGroup>
910

1011
<ItemGroup>
@@ -19,11 +20,12 @@
1920

2021
<ItemGroup>
2122
<!--Get the latest released version of UnitsNet.Serialization.JsonNet in Nuget-->
22-
<PackageReference Include="UnitsNet.Serialization.JsonNet" Version="1.*" />
23-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
24-
<PackageReference Include="xunit" Version="2.3.1" />
25-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
26-
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta2-build3683" />
23+
<PackageReference Include="UnitsNet.Serialization.JsonNet" Version="4.0.0" />
24+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
25+
<PackageReference Include="xunit" Version="2.4.1" />
26+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
27+
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
28+
<DotNetCliToolReference Include="JetBrains.dotCover.CommandLineTools" Version="2019.1.3" />
2729
</ItemGroup>
2830

2931
<ItemGroup>

UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<RootNamespace>UnitsNet.Serialization.JsonNet.Tests</RootNamespace>
66
<LangVersion>7.3</LangVersion>
77
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
8+
<IsTestProject>true</IsTestProject>
89
</PropertyGroup>
910

1011
<ItemGroup>
@@ -14,10 +15,11 @@
1415
</ItemGroup>
1516

1617
<ItemGroup>
17-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
18-
<PackageReference Include="xunit" Version="2.3.1" />
19-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
20-
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta2-build3683" />
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
19+
<PackageReference Include="xunit" Version="2.4.1" />
20+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
21+
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
22+
<DotNetCliToolReference Include="JetBrains.dotCover.CommandLineTools" Version="2019.1.3" />
2123
</ItemGroup>
2224

2325
<ItemGroup>

UnitsNet.Serialization.JsonNet/UnitsNet.Serialization.JsonNet.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<!-- NuGet properties -->
33
<PropertyGroup>
44
<PackageId>UnitsNet.Serialization.JsonNet</PackageId>
@@ -41,9 +41,9 @@
4141

4242
<!-- NuGet references that work for both signed and unsigned -->
4343
<ItemGroup>
44-
<PackageReference Include="JetBrains.Annotations" Version="2018.3.0" PrivateAssets="All" />
44+
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" PrivateAssets="All" />
4545
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" PrivateAssets="All" />
46-
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
46+
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
4747
</ItemGroup>
4848

4949
<!-- Project references, will also generate the corresponding nuget dependencies -->

0 commit comments

Comments
 (0)