Skip to content

Commit

Permalink
UX improvement: list of failed tests. (redhat-developer#86)
Browse files Browse the repository at this point in the history
The test runner now returns a list of any tests that failed.
  • Loading branch information
nicrowe00 authored Feb 21, 2024
1 parent b3e1a81 commit cec2ad6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
28 changes: 26 additions & 2 deletions Turkey/TestOutputFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;

namespace Turkey
{
public class TestOutputFormats
{
public class NewOutput : TestOutput
{
public class FailedTest
{
public string Name{ set; get;}
public string Duration{ set; get;}
}

private List<FailedTest> failedTests = new List<FailedTest>();

public async override Task AtStartupAsync(){
Console.WriteLine("Running tests:");
}
public async override Task AfterParsingTestAsync(string name, bool enabled)
{
var nameText = string.Format("{0,-60}", name);
Expand All @@ -31,7 +44,7 @@ public async override Task AfterRunningTestAsync(string name, TestResult result,
switch (result)
{
case TestResult.Passed: resultOutput = "PASS"; break;
case TestResult.Failed: resultOutput = "FAIL"; break;
case TestResult.Failed: resultOutput = "FAIL"; failedTests.Add(new FailedTest {Name = name, Duration = elapsedTime}); break;
case TestResult.Skipped: resultOutput = "SKIP"; break;
}
Console.WriteLine($"[{resultOutput}]\t({elapsedTime})");
Expand All @@ -41,15 +54,26 @@ public async override Task AfterRunningTestAsync(string name, TestResult result,
switch (result)
{
case TestResult.Passed: resultOutput = "\u001b[32mPASS\u001b[0m"; break;
case TestResult.Failed: resultOutput = "\u001b[31mFAIL\u001b[0m"; break;
case TestResult.Failed: resultOutput = "\u001b[31mFAIL\u001b[0m"; failedTests.Add(new FailedTest {Name = name, Duration = elapsedTime}); break;
case TestResult.Skipped: resultOutput = "SKIP"; break;
}
Console.WriteLine($"[{resultOutput}]\t({elapsedTime})");
}
}

public async override Task PrintFailedTests()
{
Console.WriteLine();
Console.WriteLine("The following tests failed: ");
foreach(var test in failedTests)
{
Console.WriteLine($"{string.Format("{0,-30}", test.Name)}({test.Duration})");
}
}

public async override Task AfterRunningAllTestsAsync(TestResults results)
{
Console.WriteLine();
Console.WriteLine($"Total: {results.Total} Passed: {results.Passed} Failed: {results.Failed}");
}
}
Expand Down
6 changes: 5 additions & 1 deletion Turkey/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public async virtual Task AtStartupAsync() {}
public async virtual Task BeforeTestAsync() {}
public async virtual Task AfterParsingTestAsync(string name, bool enabled) {}
public async virtual Task AfterRunningTestAsync(string name, TestResult result, StringBuilder testLog, TimeSpan testTime) {}
public async virtual Task PrintFailedTests() {}
public async virtual Task AfterRunningAllTestsAsync(TestResults results) {}
}

Expand All @@ -70,6 +71,7 @@ public TestRunner(SystemUnderTest system, DirectoryInfo root, bool verboseOutput

public async Task<TestResults> ScanAndRunAsync(List<TestOutput> outputs, string logDir, TimeSpan defaultTimeout)
{

await outputs.ForEachAsync(output => output.AtStartupAsync());

TestResults results = new TestResults();
Expand Down Expand Up @@ -148,7 +150,9 @@ public async Task<TestResults> ScanAndRunAsync(List<TestOutput> outputs, string
}

await outputs.ForEachAsync(output => output.AfterRunningTestAsync(testName, testResult, testLog, testTimeWatch.Elapsed));
}
}

await outputs.ForEachAsync(outputs => outputs.PrintFailedTests());

await outputs.ForEachAsync(output => output.AfterRunningAllTestsAsync(results));

Expand Down

0 comments on commit cec2ad6

Please sign in to comment.