Skip to content
Closed
Show file tree
Hide file tree
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
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Options.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
Expand All @@ -64,6 +65,14 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser">
<Version>1.9.71</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>10.0.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
28 changes: 28 additions & 0 deletions NUnit HTML Report Generator/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommandLine;
using CommandLine.Text;

namespace Jatech.NUnit
{
public class Options
{
[Option("input",HelpText = "input file",Required = true)]
public string Input { get; set; }

[Option("output",HelpText = "output file",Required = false)]
public string Output { get; set; }

[Option("summary", HelpText = "json file containing all addition info you want to dispaly in the test runner",Required = false)]
public string Summary { get; set; }

[HelpOption]
public string GetCorrectSytax()
{
return HelpText.AutoBuild(this, (HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current));
}
}
}
110 changes: 28 additions & 82 deletions NUnit HTML Report Generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// </summary>
#endregion

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -42,21 +44,11 @@ public class Program
{
#region Private Constants

/// <summary>
/// Usage example.
/// </summary>
private const string Usage = "Usage: NUnitHTMLReportGenerator.exe [input-path] [output-path]";

/// <summary>
/// Regular expression for acceptable characters in html id.
/// </summary>
private static readonly Regex Regex = new Regex("[^a-zA-Z0-9 -]");

/// <summary>
/// Switches for displaying the basic help when executed.
/// </summary>
private static readonly List<string> HelpParameters = new List<string>() { "?", "/?", "help" };

#endregion

#region Main
Expand All @@ -69,97 +61,36 @@ static void Main(string[] args)
{
StringBuilder html = new StringBuilder();
bool ok = false;
string input = string.Empty, output = string.Empty;

if (args.Length == 1)
{
input = args[0];

// Check if the user wants help, otherwise assume its a
// filename that needs to be processed
if (HelpParameters.Contains(input))
{
Console.WriteLine(Usage);
}
else
{
// Output file with the same name in the same folder
// with a html extension
output = Path.ChangeExtension(input, "html");
Options options = new Options();

// Check input file exists and output file doesn't
ok = CheckInputAndOutputFile(input, output);
}
}
else if (args.Length == 2)
if(!CommandLine.Parser.Default.ParseArguments(args,options))
{
// If two parameters are passed, assume the first is
// the input path and the second the output path
input = args[0];
output = args[1];

// Check input file exists and output file doesn't
ok = CheckInputAndOutputFile(input, output);
Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);
}
else

if(options.Output == null)
{
// Display the usage message
Console.WriteLine(Usage);
options.Output = Path.GetDirectoryName(options.Input) + "\\" + Path.GetFileNameWithoutExtension(options.Input) + ".html";
}

// If input file exists and output doesn't exist
if (ok)
if (File.Exists(options.Input))
{
// Generate the HTML page
html.Append(GetHTML5Header("Results"));
html.Append(ProcessFile(input));
html.Append(ProcessFile(options.Input,options.Summary));
html.Append(GetHTML5Footer());

// Save HTML to the output file
File.WriteAllText(output, html.ToString());
File.WriteAllText(options.Output, html.ToString());
}
}

#endregion

#region Private Methods

#region File Access

/// <summary>
/// Check input and output file existence
/// Input file should exist, output file should not
/// </summary>
/// <param name="input">The input file name</param>
/// <param name="output">The output name</param>
/// <returns>
/// true if it succeeds, false if it fails.
/// </returns>
private static bool CheckInputAndOutputFile(string input, string output)
{
bool ok = false;

if (File.Exists(input))
{
if (!File.Exists(output))
{
ok = true;
}
else
{
Console.WriteLine(string.Format("Output file '{0}' already exists", output));
}
}
else
{
Console.WriteLine("File does not exist");
}

return ok;
}

#endregion

#region Processing

/// <summary>
Expand All @@ -169,7 +100,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,string summery)
{
StringBuilder html = new StringBuilder();
XElement doc = XElement.Load(file);
Expand Down Expand Up @@ -202,7 +133,22 @@ private static string ProcessFile(string file)
html.AppendLine("<div class=\"row\">");
html.AppendLine("<div class=\"col-md-12\">");
html.AppendLine("<div class=\"panel panel-default\">");
html.AppendLine(string.Format("<div class=\"panel-heading\">Summary - <small>{0}</small></div>", testName));
html.AppendLine("<div class=\"panel-heading\">");

string style = "margin:0px;";
html.AppendLine(string.Format("<h4 style={0}>Summary</h4>",style));

if (summery == null)
html.AppendLine(string.Format("<p style={1}>Test Assembly - <small>{0}</small></p>", testName,style));
else
{
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(summery);
foreach(KeyValuePair<string,string> kv in dict)
{
html.AppendLine(string.Format("<p style={2}>{0} - <small>{1}</small></p>", kv.Key, kv.Value,style));
}
}
html.AppendLine("</div>");
html.AppendLine("<div class=\"panel-body\">");

html.AppendLine(string.Format("<div class=\"col-md-2 col-sm-4 col-xs-6 text-center\"><div class=\"stat\">Tests</div><div class=\"val ignore-val\">{0}</div></div>", testTests));
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ This project is used to convert NUnit (V2) generated XML result files into a sel
Included in the project is an example NUnit XML results file originally found at [vincentp-tests playground](https://github.com/vincentp-test/playground/blob/master/test-results.xml). The project has a debug command line arguement set in the project settings that will pass the filename of the example file into the software to generate a HTML file. Clicking the Start Debugging/F5 button in visual studio will run the software and generate a HTML file based on the example XML file. The output file will be found in the same directory as your executable (bin).

##Standard Usage
Download the latest release from the [releases page](https://github.com/JatechUK/NUnit-HTML-Report-Generator/releases) and extract the files onto your machine. The application can be called from the command line as follows:
`NUnitHTMLReportGenerator.exe [input-path] [output-path]`
NUnitHTMLReportGenerator.exe --input [input-path] --output(optional) [output-path] --summary(optional) [Json Script, Example: {\"Title\":\"Hello\",\"Pizza\":\"Bagle\"}]`

##Disclaimer
This project is maintained by [Luke Browning](http://github.com/luke-browning) on behalf of [Jatech](http://github.com/JatechUK) and is released under the [GPLv2.0](https://raw.githubusercontent.com/JatechUK/NUnit-HTML-Report-Generator/master/LICENSE).