public void AcceptanceTest() { string code = @" using Xunit; public class TestClass { [Fact] public void TestMethod() { } }"; using (MockAssembly assembly = new MockAssembly()) { assembly.Compile(code); XmlNode lastNode = null; XmlNode returnValue = null; using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false)) returnValue = wrapper.RunTest("TestClass", "TestMethod", node => { lastNode = node; return(true); }); XmlNode resultNode = ResultXmlUtility.GetResult(lastNode); Assert.Equal("Pass", resultNode.Attributes["result"].Value); Assert.Equal(returnValue, lastNode); } }
public void NonTestMethodInClassWithTestMethod() { string code = @" using Xunit; public class TestClass { public void NonTestMethod() { } [Fact] public void TestMethod() { } }"; using (MockAssembly assembly = new MockAssembly()) { assembly.Compile(code); XmlNode lastNode = null; using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false)) wrapper.RunTest("TestClass", "NonTestMethod", node => { lastNode = node; return(true); }); Assert.Equal("class", lastNode.Name); Assert.Equal(0, lastNode.ChildNodes.Count); // Empty class node } }
static string Run(string className, System.Reflection.Assembly koanAssembly, ExecutorWrapper wrapper) { Type classToRun = koanAssembly.GetType(className); if (classToRun == null) { return("(0/0)"); } string[] queue = new string[classToRun.GetMethods().Length + 1]; int highestKoanNumber = 0; foreach (MethodInfo method in classToRun.GetMethods()) { if (method.Name == null) { continue; } DotNetKoans.KoanAttribute custAttr = method.GetCustomAttributes(typeof(DotNetKoans.KoanAttribute), false).FirstOrDefault() as DotNetKoans.KoanAttribute; if (custAttr == null) { continue; } queue[custAttr.Position] = method.Name; if (custAttr.Position > highestKoanNumber) { highestKoanNumber = custAttr.Position; } } int numberOfTestsActuallyRun = 0; int numberOfTestsPassed = 0; foreach (string test in queue) { if (String.IsNullOrEmpty(test)) { continue; } numberOfTestsActuallyRun++; if (TEST_FAILED != 0) { continue; } wrapper.RunTest(className, test, callback); if (TEST_FAILED == 0) { numberOfTestsPassed++; } } if (numberOfTestsActuallyRun != highestKoanNumber) { Console.WriteLine("!!!!WARNING - Some Koans appear disabled. The highest koan found was {0} but we ran {1} koan(s)", highestKoanNumber, numberOfTestsActuallyRun); } return(string.Format("({0}/{1})", numberOfTestsPassed, numberOfTestsActuallyRun)); }
/// <summary> /// Run a single unit test /// </summary> /// <param name="assemblyPath">The assembly that contains the unit test.</param> /// <param name="className">The full name of the class that contains the unit test.</param> /// <param name="methodName">The name of the unit test method</param> override public void RunTests(string assemblyPath, string assemblyName, string className, string methodName) { System.Xml.XmlNode returnValue = null; using (ExecutorWrapper wrapper = new ExecutorWrapper(assemblyPath, null, true)) { returnValue = wrapper.RunTest(className, methodName, node => true); } ParseResults(returnValue); }
public void InvalidMethodName() { string code = @" using Xunit; public class TestClass { }"; using (MockAssembly assembly = new MockAssembly()) { assembly.Compile(code); using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false)) Assert.Throws <ArgumentException>(() => wrapper.RunTest("TestClass", "DummyMethod", null)); } }