Skip to content

Commit d8ebbf5

Browse files
committed
test: add code coverage support
1 parent 0c14953 commit d8ebbf5

File tree

4 files changed

+78
-57
lines changed

4 files changed

+78
-57
lines changed

.gitignore

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -86,38 +86,10 @@ _ReSharper*/
8686
*.[Rr]e[Ss]harper
8787
*.DotSettings.user
8888

89-
# JustCode is a .NET coding addin-in
90-
.JustCode
91-
92-
# TeamCity is a build add-in
93-
_TeamCity*
9489

9590
# DotCover is a Code Coverage Tool
9691
*.dotCover
9792

98-
# NCrunch
99-
_NCrunch_*
100-
.*crunch*.local.xml
101-
102-
# MightyMoose
103-
*.mm.*
104-
AutoTest.Net/
105-
106-
# Web workbench (sass)
107-
.sass-cache/
108-
109-
# Installshield output folder
110-
[Ee]xpress/
111-
112-
# DocProject is a documentation generator add-in
113-
DocProject/buildhelp/
114-
DocProject/Help/*.HxT
115-
DocProject/Help/*.HxC
116-
DocProject/Help/*.hhc
117-
DocProject/Help/*.hhk
118-
DocProject/Help/*.hhp
119-
DocProject/Help/Html2
120-
DocProject/Help/html
12193

12294
# Click-Once directory
12395
publish/
@@ -193,3 +165,5 @@ _internal_/
193165
TestData/
194166
Output/
195167
ToDo.txt
168+
.tests/
169+
Fossology.Rest.Dotnet.Test/coverage.cobertura.xml

CodeCoverageReport.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -------------------------------------------------------
2+
# Create Code Covergae Report - Powershell based approach
3+
# -------------------------------------------------------
4+
5+
$testfolder = "./.tests"
6+
7+
# 1. Remove all TestResult folders and files
8+
Write-Host "Removing all 'TestResults' folders..."
9+
$testfolders = Get-ChildItem -Path . "TestResults" -Recurse -Directory
10+
foreach ($folder in $testfolders) {
11+
Remove-Item $folder.FullName -Recurse
12+
}
13+
14+
Write-Host "Removing all 'coverage.cobertura.xml' files..."
15+
$coberturaFiles = Get-ChildItem -Path . "coverage.cobertura.xml" -Recurse
16+
foreach ($file in $coberturaFiles) {
17+
Remove-Item $file.FullName
18+
}
19+
20+
# 2. Run tests
21+
Write-Host "Running unit tests..."
22+
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
23+
24+
# 3 Generate reports
25+
Write-Host "Generating reports..."
26+
$coberturaFiles = Get-ChildItem -Path . "coverage.cobertura.xml" -Recurse
27+
$list = ""
28+
for ($i=0; $i -lt $coberturaFiles.Count; $i++) {
29+
$list = $list + $coberturaFiles[$i].FullName
30+
$list = $list + ";"
31+
}
32+
33+
$cmd = "-reports:" + $list
34+
$targetdir = "-targetdir:" + $testfolder + "\coverage-report"
35+
reportgenerator $cmd $targetdir -reporttypes:"Html"
36+
37+
$targetdir = "-targetdir:" + $testfolder + "\badges"
38+
reportgenerator $cmd $targetdir -reporttypes:"Badges"
39+
40+
$targetdir = "-targetdir:" + $testfolder
41+
reportgenerator $cmd $targetdir -reporttypes:"Cobertura;JsonSummary"
Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
5-
<CodeAnalysisRuleSet>..\Fossology.Rest.Dotnet.ruleset</CodeAnalysisRuleSet>
6-
<IsPackable>false</IsPackable>
7-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<CodeAnalysisRuleSet>..\Fossology.Rest.Dotnet.ruleset</CodeAnalysisRuleSet>
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
88

9-
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
11-
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
12-
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
13-
<PackageReference Include="coverlet.collector" Version="1.3.0">
14-
<PrivateAssets>all</PrivateAssets>
15-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16-
</PackageReference>
17-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
18-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
19-
<PrivateAssets>all</PrivateAssets>
20-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21-
</PackageReference>
22-
<PackageReference Include="Tethys.Logging.Console" Version="1.5.0" />
23-
</ItemGroup>
9+
<ItemGroup>
10+
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
11+
<PrivateAssets>all</PrivateAssets>
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
</PackageReference>
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
15+
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
16+
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
17+
<PackageReference Include="coverlet.collector" Version="1.3.0">
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
</PackageReference>
21+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
22+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
23+
<PrivateAssets>all</PrivateAssets>
24+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
25+
</PackageReference>
26+
<PackageReference Include="Tethys.Logging.Console" Version="1.5.0" />
27+
</ItemGroup>
2428

25-
<ItemGroup>
26-
<ProjectReference Include="..\Fossology.Rest.Dotnet.Model\Fossology.Rest.Dotnet.Model.csproj" />
27-
<ProjectReference Include="..\Fossology.Rest.Dotnet\Fossology.Rest.Dotnet.csproj" />
28-
</ItemGroup>
29+
<ItemGroup>
30+
<ProjectReference Include="..\Fossology.Rest.Dotnet.Model\Fossology.Rest.Dotnet.Model.csproj" />
31+
<ProjectReference Include="..\Fossology.Rest.Dotnet\Fossology.Rest.Dotnet.csproj" />
32+
</ItemGroup>
2933

30-
<ItemGroup>
31-
<None Include="..\.editorconfig">
32-
<Link>.editorconfig</Link>
33-
</None>
34-
</ItemGroup>
34+
<ItemGroup>
35+
<None Include="..\.editorconfig">
36+
<Link>.editorconfig</Link>
37+
</None>
38+
</ItemGroup>
3539

3640
</Project>

Fossology.Rest.Dotnet.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ EndProject
1414
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6C39AAAA-3427-4C25-80ED-2B684D09A26C}"
1515
ProjectSection(SolutionItems) = preProject
1616
.editorconfig = .editorconfig
17+
.gitignore = .gitignore
18+
CodeCoverageReport.ps1 = CodeCoverageReport.ps1
1719
EndProjectSection
1820
EndProject
1921
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fossology.Rest.Dotnet.Model", "Fossology.Rest.Dotnet.Model\Fossology.Rest.Dotnet.Model.csproj", "{8508C5AC-5A27-4E14-A366-97B7D054867B}"

0 commit comments

Comments
 (0)