From 6290f8dc763e8bc0ea2db9f555b20c1fe288d9c4 Mon Sep 17 00:00:00 2001 From: brendanconnolly Date: Fri, 21 Aug 2015 14:37:03 -0700 Subject: [PATCH 1/2] add arguement to filter modal test case details to only show failing tests --- NUnit HTML Report Generator/Program.cs | 42 ++++++++++++++++++++------ 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/NUnit HTML Report Generator/Program.cs b/NUnit HTML Report Generator/Program.cs index b6b474e..9f12da1 100644 --- a/NUnit HTML Report Generator/Program.cs +++ b/NUnit HTML Report Generator/Program.cs @@ -1,4 +1,4 @@ -#region File Header +#region File Header // // Copyright (c) 2014 Jatech Limited. All rights reserved. // @@ -45,7 +45,7 @@ public class Program /// /// Usage example. /// - private const string Usage = "Usage: NUnitHTMLReportGenerator.exe [input-path] [output-path]"; + private const string Usage = "Usage: NUnitHTMLReportGenerator.exe [input-path] [output-path] [failure-details-only]"; /// /// Regular expression for acceptable characters in html id. @@ -70,6 +70,7 @@ static void Main(string[] args) StringBuilder html = new StringBuilder(); bool ok = false; string input = string.Empty, output = string.Empty; + bool failuresOnlyFlag= false; if (args.Length == 1) { @@ -101,6 +102,18 @@ static void Main(string[] args) // Check input file exists and output file doesn't ok = CheckInputAndOutputFile(input, output); } + else if(args.Length==3) + { + // If three parameters are passed, assume the first is + // the input path and the second the output path + // third is errors only flag + input = args[0]; + output = args[1]; + failuresOnlyFlag=!string.IsNullOrEmpty(args[2]); + + // Check input file exists and output file doesn't + ok = CheckInputAndOutputFile(input, output); + } else { // Display the usage message @@ -112,7 +125,7 @@ static void Main(string[] args) { // Generate the HTML page html.Append(GetHTML5Header("Results")); - html.Append(ProcessFile(input)); + html.Append(ProcessFile(input,failuresOnlyFlag)); html.Append(GetHTML5Footer()); // Save HTML to the output file @@ -169,7 +182,7 @@ private static bool CheckInputAndOutputFile(string input, string output) /// /// HTML page content. /// - private static string ProcessFile(string file) + private static string ProcessFile(string file, bool failuresOnlyFlag) { StringBuilder html = new StringBuilder(); XElement doc = XElement.Load(file); @@ -224,7 +237,7 @@ private static string ProcessFile(string file) html.AppendLine(""); // Process test fixtures - html.Append(ProcessFixtures(doc.Descendants("test-suite").Where(x => x.Attribute("type").Value == "TestFixture"))); + html.Append(ProcessFixtures(doc.Descendants("test-suite").Where(x => x.Attribute("type").Value == "TestFixture"),failuresOnlyFlag)); // End container html.AppendLine(""); @@ -240,7 +253,7 @@ private static string ProcessFile(string file) /// /// Fixtures as HTML. /// - private static string ProcessFixtures(IEnumerable fixtures) + private static string ProcessFixtures(IEnumerable fixtures, bool failuresOnlyFlag) { StringBuilder html = new StringBuilder(); int index = 0; @@ -336,7 +349,7 @@ private static string ProcessFixtures(IEnumerable fixtures) // Generate the modal dialog that will be shown // if the user clicks on the test-fixtures - html.AppendLine(GenerateFixtureModal(fixture, modalId, fixtureName, fixtureReason)); + html.AppendLine(GenerateFixtureModal(fixture, modalId, fixtureName, fixtureReason,failuresOnlyFlag)); html.AppendLine(""); html.AppendLine(""); @@ -453,7 +466,7 @@ private static string GeneratePrintableView(XElement fixture, string warningMess /// /// The dialogs HTML. /// - private static string GenerateFixtureModal(XElement fixture, string modalId, string title, string warningMessage) + private static string GenerateFixtureModal(XElement fixture, string modalId, string title, string warningMessage, bool failuresOnlyFlag) { StringBuilder html = new StringBuilder(); @@ -477,13 +490,21 @@ private static string GenerateFixtureModal(XElement fixture, string modalId, str // Add each test case to the dialog, colour // coded based on the result - foreach (var testCase in fixture.Descendants("test-case")) + var testcasesToInclude=fixture.Descendants("test-case"); + + if(failuresOnlyFlag) + { + testcasesToInclude=fixture.Descendants("test-case").Where(t => t.Attribute("result").Value.ToLower() == "failure"); + } + + foreach (var testCase in testcasesToInclude) { + // Get properties name = testCase.Attribute("name").Value; result = testCase.Attribute("result").Value; - // Remove namespace if included + // Remove namespace if included name = name.Substring(name.LastIndexOf('.') + 1, name.Length - name.LastIndexOf('.') - 1); html.AppendLine("
From 4210c1a5bd75400e84376106efaf1545d2f5e2e0 Mon Sep 17 00:00:00 2001 From: brendanconnolly Date: Tue, 25 Aug 2015 16:33:50 -0700 Subject: [PATCH 2/2] include tests with error result when failureOnly flag enabled To match the report output include test cases that error in the modal when failures only parameter is specified --- NUnit HTML Report Generator/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NUnit HTML Report Generator/Program.cs b/NUnit HTML Report Generator/Program.cs index 9f12da1..2482ae4 100644 --- a/NUnit HTML Report Generator/Program.cs +++ b/NUnit HTML Report Generator/Program.cs @@ -494,7 +494,7 @@ private static string GenerateFixtureModal(XElement fixture, string modalId, str if(failuresOnlyFlag) { - testcasesToInclude=fixture.Descendants("test-case").Where(t => t.Attribute("result").Value.ToLower() == "failure"); + testcasesToInclude=fixture.Descendants("test-case").Where(t => t.Attribute("result").Value.ToLower() == "failure" || t.Attribute("result").Value.ToLower() == "error"); } foreach (var testCase in testcasesToInclude)