Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test summaries #2118

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
75 changes: 58 additions & 17 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")), completeOnFailure: true);
IT-VBFK marked this conversation as resolved.
Show resolved Hide resolved

ReportTestOutcome(globFilters: $"*{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 All @@ -173,6 +179,8 @@ class Build : NukeBuild
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
{
const string NET47 = "net47";

DotNetTest(s => s
.SetConfiguration(Configuration.Debug)
.SetProcessEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en-US")
Expand All @@ -187,19 +195,45 @@ class Build : NukeBuild
(_, project) => _
.SetProjectFile(project)
.CombineWith(
project.GetTargetFrameworks().Except(new[] { "net47" }),
(_, framework) => _.SetFramework(framework)
project.GetTargetFrameworks().Except(new[] { NET47 }),
(_, framework) => _
.SetFramework(framework)
.AddLoggers($"trx;LogFileName={project.Name}_{framework}.trx")
)
)
), completeOnFailure: true
);

ReportTestOutcome(globFilters: $"*[!*{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(params string[] globFilters)
{
var resultFiles = TestResultsDirectory.GlobFiles(globFilters);
var outcomes = resultFiles.SelectMany(Outcomes).ToList();
var passedTests = outcomes.Count(outcome => outcome is "Passed");
var failedTests = outcomes.Count(outcome => outcome is "Failed");
var skippedTests = outcomes.Count(outcome => outcome is "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 All @@ -223,14 +257,16 @@ class Build : NukeBuild
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
{
var projects = new[]
{
Solution.TestFrameworks.MSpec_Specs,
Solution.TestFrameworks.MSTestV2_Specs,
Solution.TestFrameworks.NUnit3_Specs,
Solution.TestFrameworks.XUnit2_Specs
};

var testCombinations =
from project in new[]
{
Solution.TestFrameworks.MSpec_Specs,
Solution.TestFrameworks.MSTestV2_Specs,
Solution.TestFrameworks.NUnit3_Specs,
Solution.TestFrameworks.XUnit2_Specs
}
from project in projects
let frameworks = project.GetTargetFrameworks()
let supportedFrameworks = EnvironmentInfo.IsWin ? frameworks : frameworks.Except(new[] { "net47" })
from framework in supportedFrameworks
Expand All @@ -247,12 +283,17 @@ class Build : NukeBuild
"DoesNotReturnAttribute")
.CombineWith(
testCombinations,
(_, v) => _.SetProjectFile(v.project).SetFramework(v.framework)));
(_, v) => _
.SetProjectFile(v.project)
.SetFramework(v.framework)
.AddLoggers($"trx;LogFileName={v.project.Name}_{v.framework}.trx")), completeOnFailure: true);

if (EnvironmentInfo.IsWin)
{
NSpec3(Solution.TestFrameworks.NSpec3_Net47_Specs.Directory / "bin" / "Debug" / "net47" / "NSpec3.Specs.dll");
}

ReportTestOutcome(projects.Select(p => $"*{p.Name}*.trx").ToArray());
});

Target Pack => _ => _
Expand All @@ -265,7 +306,7 @@ class Build : NukeBuild
.Executes(() =>
{
ReportSummary(s => s
.WhenNotNull(SemVer,(_, semVer) => _
.WhenNotNull(SemVer, (_, semVer) => _
.AddPair("Packed version", semVer)));

DotNetPack(s => s
Expand Down