Skip to content

Commit 9c159bb

Browse files
authored
Add codecoverage (#21)
* Add codecoverage * Add coverlet tool * add codecov
1 parent f2441f5 commit 9c159bb

3 files changed

Lines changed: 57 additions & 6 deletions

File tree

CommandLineParser.Tests/CommandLineParser.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14+
<PackageReference Include="coverlet.msbuild" Version="2.5.0">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
17+
</PackageReference>
1418
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
1519
<PackageReference Include="Moq" Version="4.10.0" />
1620
<PackageReference Include="xunit" Version="2.4.0" />

build.cake

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#tool "nuget:?package=xunit.runner.console&version=2.2.0"
2+
#tool nuget:?package=Codecov
3+
#addin nuget:?package=Cake.Codecov
4+
#addin nuget:?package=Cake.Coverlet
25
///////////////////////////////////////////////////////////////////////////////
36
// ARGUMENTS
47
///////////////////////////////////////////////////////////////////////////////
@@ -17,6 +20,7 @@ var nuspecFile = $"./{project}/{project}.nuspec";
1720
var tests = $"./{project}.Tests/{project}.Tests.csproj";
1821
var publishPath = MakeAbsolute(Directory("./output"));
1922
var nugetPackageDir = MakeAbsolute(Directory("./nuget"));
23+
var codeCoverageOutput = MakeAbsolute(Directory("./code-coverage/"));
2024

2125
///////////////////////////////////////////////////////////////////////////////
2226
// TASKS
@@ -49,12 +53,29 @@ Task("Test")
4953
.IsDependentOn("Build")
5054
.Does( () => {
5155

56+
var coverletSettings = new CoverletSettings {
57+
CollectCoverage = true,
58+
CoverletOutputDirectory = codeCoverageOutput,
59+
CoverletOutputFormat = CoverletOutputFormat.opencover,
60+
CoverletOutputName = $"coverage.xml"
61+
};
62+
5263
DotNetCoreTest(tests,
53-
new DotNetCoreTestSettings {
54-
NoBuild = true,
55-
NoRestore = true,
56-
Configuration = configuration
57-
});
64+
new DotNetCoreTestSettings {
65+
NoBuild = true,
66+
NoRestore = true,
67+
Configuration = configuration
68+
}, coverletSettings);
69+
70+
Information("Print all files: ");
71+
foreach(var file in GetFiles($".\\**\\**\\**\\*.*"))
72+
{
73+
Information(file.FullPath);
74+
}
75+
76+
77+
// Upload a coverage report.
78+
Codecov($"{codeCoverageOutput}\\coverage.xml");
5879
});
5980

6081
Task("Publish")
@@ -78,7 +99,7 @@ Task("Publish-NuGet")
7899
{
79100
BasePath = publishPath,
80101
OutputDirectory = nugetPackageDir,
81-
IncludeReferencedProjects = true,
102+
IncludeReferencedProjects = false,
82103

83104
Properties = new Dictionary<string, string>
84105
{

codecov.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
codecov:
2+
notify:
3+
require_ci_to_pass: yes
4+
5+
coverage:
6+
precision: 2
7+
round: down
8+
range: "25...75"
9+
10+
status:
11+
project: yes
12+
patch: yes
13+
changes: no
14+
15+
parsers:
16+
gcov:
17+
branch_detection:
18+
conditional: yes
19+
loop: yes
20+
method: no
21+
macro: no
22+
23+
comment:
24+
layout: "header, diff, changes, sunburst, uncovered"
25+
behavior: default
26+
require_changes: no

0 commit comments

Comments
 (0)