Skip to content

Commit

Permalink
Merge pull request #1820 from jnyrup/CodeCoverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed Feb 19, 2022
2 parents a68ab33 + 2d580c2 commit c84205e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .nuke/build.schema.json
Expand Up @@ -78,6 +78,7 @@
"ApiChecks",
"CalculateNugetVersion",
"Clean",
"CodeCoverage",
"Compile",
"Pack",
"Push",
Expand All @@ -100,6 +101,7 @@
"ApiChecks",
"CalculateNugetVersion",
"Clean",
"CodeCoverage",
"Compile",
"Pack",
"Push",
Expand Down
33 changes: 27 additions & 6 deletions Build/Build.cs
Expand Up @@ -115,13 +115,18 @@ class Build : NukeBuild
.DependsOn(Compile)
.Executes(() =>
{
Project[] projects = new[]
{
Solution.Specs.FluentAssertions_Specs,
Solution.Specs.FluentAssertions_Equivalency_Specs
};
if (EnvironmentInfo.IsWin)
{
Xunit2(s =>
{
IReadOnlyCollection<string> testAssemblies = GlobFiles(
Solution.Specs.FluentAssertions_Specs.Directory,
"bin/Debug/net47/*.Specs.dll");
IEnumerable<string> testAssemblies = projects
.SelectMany(project => GlobFiles(project.Directory, "bin/Debug/net47/*.Specs.dll"));
Assert.NotEmpty(testAssemblies.ToList());
Expand All @@ -132,20 +137,33 @@ class Build : NukeBuild
}
DotNetTest(s => s
.SetProjectFile(Solution.Specs.FluentAssertions_Specs)
.SetConfiguration("Debug")
.EnableNoBuild()
.SetDataCollector("XPlat Code Coverage")
.SetResultsDirectory(RootDirectory / "TestResults")
.CombineWith(
Solution.Specs.FluentAssertions_Specs.GetTargetFrameworks().Except(new[] { "net47" }),
(_, v) => _.SetFramework(v)));
projects,
(_, project) => _
.SetProjectFile(project)
.CombineWith(
project.GetTargetFrameworks().Except(new[] { "net47" }),
(_, framework) => _.SetFramework(framework)
)
)
);
});

Target CodeCoverage => _ => _
.DependsOn(TestFrameworks)
.DependsOn(UnitTests)
.Executes(() =>
{
ReportGenerator(s => s
.SetProcessToolPath(ToolPathResolver.GetPackageExecutable("ReportGenerator", "ReportGenerator.dll", framework: "net5.0"))
.SetTargetDirectory(RootDirectory / "TestResults" / "reports")
.AddReports(RootDirectory / "TestResults/**/coverage.cobertura.xml")
.AddReportTypes("HtmlInline_AzurePipelines_Dark", "lcov")
.SetClassFilters("-System.Diagnostics.CodeAnalysis.StringSyntaxAttribute")
.SetAssemblyFilters("+FluentAssertions"));
string link = RootDirectory / "TestResults" / "reports" / "index.html";
Expand Down Expand Up @@ -173,6 +191,8 @@ class Build : NukeBuild
DotNetTest(s => s
.SetConfiguration("Debug")
.EnableNoBuild()
.SetDataCollector("XPlat Code Coverage")
.SetResultsDirectory(RootDirectory / "TestResults")
.CombineWith(
testCombinations,
(_, v) => _.SetProjectFile(v.project).SetFramework(v.framework)));
Expand All @@ -187,6 +207,7 @@ class Build : NukeBuild
.DependsOn(ApiChecks)
.DependsOn(TestFrameworks)
.DependsOn(UnitTests)
.DependsOn(CodeCoverage)
.DependsOn(CalculateNugetVersion)
.Executes(() =>
{
Expand Down
3 changes: 3 additions & 0 deletions Tests/TestFrameworks/MSTestV2.Specs/MSTestV2.Specs.csproj
Expand Up @@ -9,6 +9,9 @@
<ProjectReference Include="..\..\..\Src\FluentAssertions\FluentAssertions.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.2" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
Expand Down
3 changes: 3 additions & 0 deletions Tests/TestFrameworks/MSpec.Specs/MSpec.Specs.csproj
Expand Up @@ -9,6 +9,9 @@
<ProjectReference Include="..\..\..\Src\FluentAssertions\FluentAssertions.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.2" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Machine.Specifications" Version="1.0.0" />
<PackageReference Include="Machine.Specifications.Runner.VisualStudio" Version="2.10.2" />
Expand Down
3 changes: 3 additions & 0 deletions Tests/TestFrameworks/NUnit3.Specs/NUnit3.Specs.csproj
Expand Up @@ -9,6 +9,9 @@
<ProjectReference Include="..\..\..\Src\FluentAssertions\FluentAssertions.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.2" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1">
Expand Down

0 comments on commit c84205e

Please sign in to comment.