Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions NUnit HTML Report Generator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region File Header
#region File Header
// <copyright application="NUnit HTML Report Generator" file="Program.cs" company="Jatech Limited">
// Copyright (c) 2014 Jatech Limited. All rights reserved.
//
Expand Down Expand Up @@ -45,7 +45,7 @@ public class Program
/// <summary>
/// Usage example.
/// </summary>
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]";

/// <summary>
/// Regular expression for acceptable characters in html id.
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -169,7 +182,7 @@ private static bool CheckInputAndOutputFile(string input, string output)
/// <returns>
/// HTML page content.
/// </returns>
private static string ProcessFile(string file)
private static string ProcessFile(string file, bool failuresOnlyFlag)
{
StringBuilder html = new StringBuilder();
XElement doc = XElement.Load(file);
Expand Down Expand Up @@ -224,7 +237,7 @@ private static string ProcessFile(string file)
html.AppendLine("</div>");

// 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("</div>");
Expand All @@ -240,7 +253,7 @@ private static string ProcessFile(string file)
/// <returns>
/// Fixtures as HTML.
/// </returns>
private static string ProcessFixtures(IEnumerable<XElement> fixtures)
private static string ProcessFixtures(IEnumerable<XElement> fixtures, bool failuresOnlyFlag)
{
StringBuilder html = new StringBuilder();
int index = 0;
Expand Down Expand Up @@ -336,7 +349,7 @@ private static string ProcessFixtures(IEnumerable<XElement> 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("</div>");
html.AppendLine("</div>");
Expand Down Expand Up @@ -453,7 +466,7 @@ private static string GeneratePrintableView(XElement fixture, string warningMess
/// <returns>
/// The dialogs HTML.
/// </returns>
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();

Expand All @@ -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" || t.Attribute("result").Value.ToLower() == "error");
}

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("<div class=\"panel ");
Expand Down Expand Up @@ -540,6 +561,7 @@ private static string GenerateFixtureModal(XElement fixture, string modalId, str
return html.ToString();
}


#region HTML5 Template

/// <summary>
Expand Down