Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Nunit] Nunit Short Path Finder App. Works in linqpad also.
class Program
{
static void Main(string[] args)
{
XDocument xDocument;
using (XmlReader xr = XmlReader.Create(@"c:\Users\akramarev\Downloads\TestResultSet.xml"))
{
xDocument = XDocument.Load(xr);
}
var testElements = xDocument.XPathSelectElements(@"//test-suite[@type=""TestFixture""]")
.Select(e => new TestElement(e));
PrintOutTestCases(testElements);
}
private static void PrintOutTestCases(IEnumerable<TestElement> testElements, int level = 0)
{
foreach (var testElement in testElements.OrderByDescending(c => c.Time).Take(10))
{
Console.WriteLine($"{new String(' ', level)}{testElement.Time} {testElement.Name}");
if (testElement.SuiteType != null)
{
var testCases = testElement.Element.XPathSelectElements(@"./results/test-suite | ./results/test-case")
.Select(e => new TestElement(e));
PrintOutTestCases(testCases, level + 2);
}
}
}
public class TestElement
{
public string Name { get; set; }
public double Time { get; set; }
public string SuiteType { get; set; }
public XElement Element { get; set; }
public TestElement(XElement e)
{
Name = e.Attribute("name")?.Value;
Time = Convert.ToDouble(e.Attribute("time")?.Value);
SuiteType = e.Attribute("type")?.Value;
Element = e;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.