Is there a tool to merge NUnit result files? - nunit

For unclear reasons my Nunit test fixture cannot be executed in a single run, so I'm forced to execute a few tests in separate runs. However this means that the test results are splitted over multiple output files.
Is there a tool available which can merge NUnit result XML files into a single XML file?
I've tried using the existing Nunit-summary tool, but this simply sequentially parses the XML files with the given XSL file and concatenates the result as one big file.
Instead I would like it to merge/group the results for the test cases into the right namespaces/testfixtures first and then feed it to the XSLT processor. This way all test results should be displayed by fixture even though they're not gathered in a single run.

This is probably too late to help you, but we recently encountered a similar issue and wrote a small open source tool to help out: https://github.com/15below/NUnitMerger
From the readme:
Using in MSBuild
Load the task:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
ToolsVersion="4.0"
DefaultTargets="Build">
<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\..\Tools\MSBuild\15below.NUnitMerger.dll" TaskName="FifteenBelow.NUnitMerger.MSBuild.NUnitMergeTask" />
...
Feed it an array of files with in a target:
<Target Name="UnitTest" DependsOnTargets="OtherThings">
... Generate the individual files here in $(TestResultsDir) ...
<ItemGroup>
<ResultsFiles Include="$(TestResultsDir)\*.xml" />
</ItemGroup>
<NUnitMergeTask FilesToBeMerged="#(ResultsFiles)" OutputPath="$(MSBuildProjectDirectory)\TestResult.xml" />
</Target>
Find the resulting combined results at OutputPath.
Using in F#
Create an F# console app and add 15below.NUnitMerger.dll, System.Xml and System.Xml.Linq as references.
open FifteenBelow.NUnitMerger.Core
open System.IO
open System.Xml.Linq
// All my files are in one directory
WriteMergedNunitResults (#"..\testdir", "*.xml", "myMergedResults.xml")
// I want files from all over the place
let myFiles = ... some filenames as a Seq
myFiles
|> Seq.map (fun fileName -> XDocument.Parse(File.ReadAllText(fileName)))
|> FoldDocs
|> CreateMerged
|> fun x -> File.WriteAllText("myOtherMergedResults.xml", x.ToString())

I was using the 15below NUnitMerger above for a while, but wanted to extend it and since my F# skills are not good enough to do it there, I inspected their mechanism and implemented the following class in C# to achieve the same thing. Here is my starting code which might help anyone who also want to do this kind of manipulation in C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Text;
namespace RunNUnitTests
{
public static class NUnitMerger
{
public static bool MergeFiles(IEnumerable<string> files, string output)
{
XElement environment = null;
XElement culture = null;
var suites = new List<XElement>();
bool finalSuccess = true;
string finalResult = "";
double totalTime = 0;
int total = 0, errors = 0, failures = 0, notrun = 0, inconclusive = 0, ignored = 0, skipped = 0, invalid = 0;
foreach (var file in files)
{
var doc = XDocument.Load(file);
var tr = doc.Element("test-results");
if (environment == null)
environment = tr.Element("environment");
if (culture == null)
culture = tr.Element("culture-info");
total += Convert.ToInt32(tr.Attribute("total").Value);
errors += Convert.ToInt32(tr.Attribute("errors").Value);
failures += Convert.ToInt32(tr.Attribute("failures").Value);
notrun += Convert.ToInt32(tr.Attribute("not-run").Value);
inconclusive += Convert.ToInt32(tr.Attribute("inconclusive").Value);
ignored += Convert.ToInt32(tr.Attribute("ignored").Value);
skipped += Convert.ToInt32(tr.Attribute("skipped").Value);
invalid += Convert.ToInt32(tr.Attribute("invalid").Value);
var ts = tr.Element("test-suite");
string result = ts.Attribute("result").Value;
if (!Convert.ToBoolean(ts.Attribute("success").Value))
finalSuccess = false;
totalTime += Convert.ToDouble(ts.Attribute("time").Value);
if (finalResult != "Failure" && (String.IsNullOrEmpty(finalResult) || result == "Failure" || finalResult == "Success"))
finalResult = result;
suites.Add(ts);
}
if (String.IsNullOrEmpty(finalResult))
{
finalSuccess = false;
finalResult = "Inconclusive";
}
var project = XElement.Parse(String.Format("<test-suite type=\"Test Project\" name=\"\" executed=\"True\" result=\"{0}\" success=\"{1}\" time=\"{2}\" asserts=\"0\" />", finalResult, finalSuccess ? "True" : "False", totalTime));
var results = XElement.Parse("<results/>");
results.Add(suites.ToArray());
project.Add(results);
var now = DateTime.Now;
var trfinal = XElement.Parse(String.Format("<test-results name=\"Merged results\" total=\"{0}\" errors=\"{1}\" failures=\"{2}\" not-run=\"{3}\" inconclusive=\"{4}\" ignored=\"{5}\" skipped=\"{6}\" invalid=\"{7}\" date=\"{8}\" time=\"{9}\" />", total, errors, failures, notrun, inconclusive, ignored, skipped, invalid, now.ToString("yyyy-MM-dd"), now.ToString("HH:mm:ss")));
trfinal.Add(new[] { environment, culture, project });
trfinal.Save(output);
return finalSuccess;
}
}
}

I read on the web that Nunit result files are XML so i guess you can merge the file with an ordinary merge software as WinMerge

Related

Analyzer creating multiple diagnostics for compilation unit

I am writing a Roslyn Diagnostic to turn on/off option strict. Since there can only be one per file, I am using the compilation for the node to be examined:
context.RegisterSyntaxNodeAction(CompilationUnitCheck, SyntaxKind.CompilationUnit);
I am seeing multiple diagnostics displayed in the error list pane when running the development hive, at times as many as 3, but always at least 2 per file. They show the same location. What could be causing this, and what can I do to fix it?
private void CompilationUnitCheck(SyntaxNodeAnalysisContext context)
{
var orgRoot = (CompilationUnitSyntax) context.Node;
var fileName = System.IO.Path.GetFileNameWithoutExtension(orgRoot.SyntaxTree.FilePath) ;
if ((fileName?.EndsWith("designer", StringComparison.CurrentCultureIgnoreCase)).GetValueOrDefault() ||
"Reference".Equals(fileName, StringComparison.CurrentCultureIgnoreCase))
{
return;
}
if (fileName != "TestFile") return;
var newErrors = fileName == "TestFile";
var location = orgRoot.GetLocation();
string strictMsg = null ?? "Off";
var diagnostic = Diagnostic.Create(Rule, location, strictMsg);
context.ReportDiagnostic(diagnostic);
}
My current workaround is to get the hashcode of the root, and store that in a static list, if it's in the list, I don't check again.

Katalon Studio deleting groovy code from script when switching to manual or recording

Did anybody see this as well, or am I doing something wrong?
I am working on a test case with Katalon Studio, in script mode. I have some Groovy script in it, (in particular a class definition, see start of code below). When I switch mode to work in manual or record mode, and then back to script mode, the groovy code (the class declaration in the example below) has disappeared...
Not very practical! Anything that should be done to avoid this?
Many thanks!
E.
Code example:
//Katalon Imports here
class Product {
String nozo
String price_string
Number qty = 1
Number price_ht = 0
Number price_ttc = 0
Product(String nozo, String price_string, Number qty = 1) {
this.nozo = nozo
this.price_string = price_string
def get_price = (this.price_string =~/(\d+)\s(\d+\.\d{2})/)
if(get_price) {
this.price_ttc = get_price[1] + get_price[2]
}
else this.price_ttc = 0
this.price_ht = this.price_ttc / 1.2
}
def get_price_order_line_ht() {
return this.price_ht * this.qty
}
}
// Intialisation of test data
Number qty_pdt1 = 2
'Open home page'
WebUI.openBrowser('http://localhost:8080/')
'Navigate to subrange'
WebUI.doubleClick(findTestObject('Object Repository/vb_desktop/home_page_desktop_fr/a_Lampadaire'))
// Etc...

How to compare file date modified using cakebuild?

Can not find related document in http://cakebuild.net/dsl/file-operations/
The cmake compares file date automatically, I'm wondering if there is similar facility in cakebuild?
There's no automatic file date comparing in Cake. It's just .NET so you can compare using System.IO just as in regular .NET.
var fileA = new System.IO.FileInfo("./filea.txt");
var fileB = new System.IO.FileInfo("./fileb.txt");
if (fileA.LastWriteTime > fileB.LastWriteTime)
{
}
or
var modifiedA = System.IO.File.GetLastWriteTime("./filea.txt");
var modifiedB = System.IO.File.GetLastWriteTime("./fileb.txt");
if (modifiedA > modifiedB)
{
}
If you want to check if two files are identical or not then there's built-in functionality to get the hash of a given file with the CalculateFileHash alias.
var fileHashA = CalculateFileHash("filea.txt").ToHex();
var fileHashB = CalculateFileHash("fileb.txt").ToHex();
if (fileHashA != fileHashB)
{
//DIFF
}

Crystal Reports - Search Dependencies

Is there a tool that will let you search a number of different crystal reports to see where a specific Table/View/SP is being used?
Scenario is this: We have over 200 reports, so when making a change to a View or Stored Procedure it is not easy to find which reports will be affected without opening each one and checking the "Database expert" or "Datasource location".
I have tried Agent Ransack on them and it doesn't pick any table or view names up.
I never found a tool to do this, so rolled my own in C# .Net 4.0.
If the crystal report uses a 'SQL Command' instead of dragging in tables, it becomes a bit tricky. I suggest only searching for the TableName rather than the fully qualified Database.dbo.TableName - since this may have been omitted in the pasted SQL Command.
usage:
var reports = CrystalExtensions.FindUsages("C:/Reports", "table_name");
code:
namespace Crystal.Helpers
{
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using CrystalDecisions.CrystalReports.Engine;
using Microsoft.CSharp.RuntimeBinder;
public static class CrystalExtensions
{
public static List<string> FindUsages(string directory, string tableName)
{
var result = new List<string>();
foreach (var file in Directory.EnumerateFiles(directory, "*.rpt", SearchOption.AllDirectories))
{
using (var report = new ReportClass { FileName = file })
{
if (report.Database == null) continue;
var tables = report.Database.Tables.ToList();
var hasTable = tables.Any(x => x.Name == tableName || x.GetCommandText().Contains(tableName));
if (hasTable)
result.Add(file);
}
}
return result;
}
public static List<Table> ToList(this Tables tables)
{
var list = new List<Table>();
var enumerator = tables.GetEnumerator();
while (enumerator.MoveNext())
list.Add((Table)enumerator.Current);
return list;
}
public static string GetCommandText(this Table table)
{
var propertyInfo = table.GetType().GetProperty("RasTable", BindingFlags.NonPublic | BindingFlags.Instance);
try
{
return ((dynamic)propertyInfo.GetValue(table, propertyInfo.GetIndexParameters())).CommandText;
}
catch (RuntimeBinderException)
{
return ""; // for simplicity of code above, really should return null
}
}
}
}
Hope that helps!
See the question here:
Any way to search inside a Crystal Report
Another option is to roll-your-own piece of software to do it, but that might be more time consuming than you're looking for. Or, find someone who already has done this :) If you find something that works, let the rest of us know because we're all in the same boat. Good luck!

IronRuby performance issue while using Variables

Here is code of very simple expression evaluator using IronRuby
public class BasicRubyExpressionEvaluator
{
ScriptEngine engine;
ScriptScope scope;
public Exception LastException
{
get; set;
}
private static readonly Dictionary<string, ScriptSource> parserCache = new Dictionary<string, ScriptSource>();
public BasicRubyExpressionEvaluator()
{
engine = Ruby.CreateEngine();
scope = engine.CreateScope();
}
public object Evaluate(string expression, DataRow context)
{
ScriptSource source;
parserCache.TryGetValue(expression, out source);
if (source == null)
{
source = engine.CreateScriptSourceFromString(expression, SourceCodeKind.SingleStatement);
parserCache.Add(expression, source);
}
var result = source.Execute(scope);
return result;
}
public void SetVariable(string variableName, object value)
{
scope.SetVariable(variableName, value);
}
}
and here is problem.
var evaluator = new BasicRubyExpressionEvaluator();
evaluator.SetVariable("a", 10);
evaluator.SetVariable("b", 1 );
evaluator.Evaluate("a+b+2", null);
vs
var evaluator = new BasicRubyExpressionEvaluator();
evaluator.Evaluate("10+1+2", null);
First Is 25 times slower than second. Any suggestions? String.Replace is not a solution for me.
I do not think the performance you are seeing is due to variable setting; the first execution of IronRuby in a program is always going to be slower than the second, regardless of what you're doing, since most of the compiler isn't loaded in until code is actually run (for startup performance reasons). Please try that example again, maybe running each version of your code in a loop, and you'll see the performance is roughly equivalent; the variable-version does have some overhead of method-dispatch to get the variables, but that should be negligible if you run it enough.
Also, in your hosting code, how come you are holding onto ScriptScopes in a dictionary? I would hold onto CompiledCode (result of engine.CreateScriptSourceFromString(...).Compile()) instead -- as that will help a lot more in repeat runs.
you can of course first build the string something like
evaluator.Evaluate(string.format("a={0}; b={1}; a + b + 2", 10, 1))
Or you can make it a method
if instead of your script you return a method then you should be able to use it like a regular C# Func object.
var script = #"
def self.addition(a, b)
a + b + 2
end
"
engine.ExecuteScript(script);
var = func = scope.GetVariable<Func<object,object,object>>("addition");
func(10,1)
This is probably not a working snippet but it shows the general idea.