Using this
blog post as a template I am trying to get our Jasmine Specs integrated into NCrunch, but try as I may I cannot get NCrunch to even list the test method let alone run it. It runs fine in ReSharper test runner and TestDriven.net but can't see why NCrunch doesn't even see it. Source code is below, any help will be much appreciated. All of the dependencies are managed via NuGet if anyone is trying to replicate the problem.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Xml;
using FluentAssertions;
using NUnit.Framework;
namespace CancerResearchUk.Icc.Web.Tests
{
[TestFixture]
public class ClientSpecs
{
private const string TestOutputFile = "JasmineResults.xml";
private const string ChutzpahConsolePath = @"..\..\..\packages\Chutzpah.2.5.0\tools\chutzpah.console.exe";
private const string TestPagePath = @"..\..\..\CancerResearchUk.Icc.Web\AllSpecs.html";
[Test]
[TestCaseSource("JasmineSpecSource")]
public void RunJasmineSpecs(TestResult result)
{
result.Passed.Should()
.BeTrue(result.Message);
}
private static IEnumerable JasmineSpecSource()
{
var outputPath = Path.GetFullPath(TestOutputFile);
var chutzPahPath = Path.GetFullPath(ChutzpahConsolePath);
var testPagePath = Path.GetFullPath(TestPagePath);
var harness = new Process
{
StartInfo =
{
FileName = chutzPahPath,
Arguments =
String.Format("/path {0} /junit {1}", testPagePath, outputPath),
UseShellExecute = false,
CreateNoWindow = true,
WorkingDirectory = "."
}
};
harness.Start();
harness.WaitForExit();
var testOutputXml = new XmlDocument();
testOutputXml.Load(TestOutputFile);
var testSuites = testOutputXml.SelectNodes("//testsuites/testsuite");
foreach(XmlNode testSuite in testSuites)
{
var cases = testSuite.SelectNodes("testcase");
foreach(XmlNode testCase in cases)
{
var failures = testCase.SelectNodes("failure");
var testName = String.Format("{0} > {1}",
Path.GetFileName(testSuite.Attributes["name"].Value),
testCase.Attributes["name"].Value);
if(failures.Count > 0)
{
foreach(XmlNode failure in failures)
{
yield return
new TestCaseData(new TestResult()
{
Passed = false,
Message = failure.Attributes["message"].Value,
TestName = testName
}).SetName(testName);
}
}
else
{
yield return new TestCaseData(new TestResult() { Passed = true, TestName = testName }).SetName(testName);
}
}
}
File.Delete(TestOutputFile);
}
}
}