Skip to content

Commit

Permalink
Add test summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
IT-VBFK committed Jan 22, 2023
1 parent 158f801 commit 136934a
Showing 1 changed file with 42 additions and 9 deletions.
51 changes: 42 additions & 9 deletions Build/Build.cs
Expand Up @@ -118,7 +118,7 @@ class Build : NukeBuild
.Executes(() =>
{
ReportSummary(s => s
.WhenNotNull(GitVersion,(_, o) => _
.WhenNotNull(GitVersion, (_, o) => _
.AddPair("Version", o.SemVer)));
DotNetBuild(s => s
Expand All @@ -136,12 +136,18 @@ class Build : NukeBuild
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
{
Project project = Solution.Specs.Approval_Tests;
DotNetTest(s => s
.SetConfiguration(Configuration.Release)
.SetProcessEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en-US")
.EnableNoBuild()
.CombineWith(
cc => cc.SetProjectFile(Solution.Specs.Approval_Tests)));
.SetResultsDirectory(TestResultsDirectory)
.CombineWith(cc => cc
.SetProjectFile(project)
.AddLoggers($"trx;LogFileName={project.Name}.trx")));
ReportTestOutcome(globFilter: $"*{project.Name}.trx");
});

Project[] Projects => new[]
Expand All @@ -158,7 +164,7 @@ class Build : NukeBuild
{
IEnumerable<string> testAssemblies = Projects
.SelectMany(project => GlobFiles(project.Directory, "bin/Debug/net47/*.Specs.dll"));
Assert.NotEmpty(testAssemblies.ToList());
Xunit2(s => s
Expand Down Expand Up @@ -188,18 +194,43 @@ class Build : NukeBuild
.SetProjectFile(project)
.CombineWith(
project.GetTargetFrameworks().Except(new[] { "net47" }),
(_, framework) => _.SetFramework(framework)
(_, framework) => _
.SetFramework(framework)
.AddLoggers($"trx;LogFileName={project.Name}_{framework}.trx")
)
)
);
ReportTestOutcome(globFilter: "*[!*net47].trx");
});

Target UnitTests => _ => _
.DependsOn(UnitTestsNetFramework)
.DependsOn(UnitTestsNetCore);

static string[] Outcomes(AbsolutePath path)
=> XmlTasks.XmlPeek(
path,
"/xn:TestRun/xn:Results/xn:UnitTestResult/@outcome",
("xn", "http://microsoft.com/schemas/VisualStudio/TeamTest/2010")).ToArray();
void ReportTestOutcome(string globFilter)
{
var resultFiles = TestResultsDirectory.GlobFiles(globFilter);
var outcomes = resultFiles.SelectMany(Outcomes).ToList();
var passedTests = outcomes.Count(x => x == "Passed");
var failedTests = outcomes.Count(x => x == "Failed");
var skippedTests = outcomes.Count(x => x == "NotExecuted");

ReportSummary(_ => _
.When(failedTests > 0, _ => _
.AddPair("Failed", failedTests.ToString()))
.AddPair("Passed", passedTests.ToString())
.When(skippedTests > 0, _ => _
.AddPair("Skipped", skippedTests.ToString())));
}

Target CodeCoverage => _ => _
.DependsOn(TestFrameworks)
.DependsOn(TestFrameworks)
.DependsOn(UnitTests)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
Expand Down Expand Up @@ -239,15 +270,17 @@ class Build : NukeBuild
DotNetTest(s => s
.SetConfiguration(Configuration.Debug)
.SetProcessEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en-US")
.EnableNoBuild()
.SetNoBuild(SucceededTargets.Contains(Compile))
.SetDataCollector("XPlat Code Coverage")
.SetResultsDirectory(TestResultsDirectory)
.AddRunSetting(
"DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.DoesNotReturnAttribute",
"DoesNotReturnAttribute")
.CombineWith(
testCombinations,
(_, v) => _.SetProjectFile(v.project).SetFramework(v.framework)));
(_, v) => _
.SetProjectFile(v.project)
.SetFramework(v.framework)));
if (EnvironmentInfo.IsWin)
{
Expand All @@ -265,7 +298,7 @@ class Build : NukeBuild
.Executes(() =>
{
ReportSummary(s => s
.WhenNotNull(SemVer,(_, semVer) => _
.WhenNotNull(SemVer, (_, semVer) => _
.AddPair("Packed version", semVer)));
DotNetPack(s => s
Expand Down

0 comments on commit 136934a

Please sign in to comment.