public RunClass ( string type, Predicate |
||
type | string | |
callback | Predicate |
|
return |
/// <summary> /// Run all the unit tests in the class /// </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> override public void RunTests(string assemblyPath, string assemblyName, string className) { System.Xml.XmlNode returnValue = null; using (ExecutorWrapper wrapper = new ExecutorWrapper(assemblyPath, null, true)) { returnValue = wrapper.RunClass(className, node => true); } ParseResults(returnValue); }
public void Should_be_able_to_run_the_simple_example() { using (MockAssembly assembly = new MockAssembly()) { XmlNode lastNode = null; XmlNode returnValue = null; using (ExecutorWrapper wrapper = new ExecutorWrapper("Coulda.Examples.dll", null, false)) returnValue = wrapper.RunClass("Coulda.Examples.SimpleExample", node => { lastNode = node; return true; }); XmlNode resultNode = ResultXmlUtility.GetResult(lastNode); ResultXmlUtility.AssertAttribute(resultNode, "name", "My example test should be able to assert"); ResultXmlUtility.AssertAttribute(resultNode, "type", "Coulda.Examples.SimpleExample"); ResultXmlUtility.AssertAttribute(resultNode, "method", "A_simple_example"); ResultXmlUtility.AssertAttribute(resultNode, "result", "Pass"); } }
public void Should_be_able_to_have_a_failing_test() { using (MockAssembly assembly = new MockAssembly()) { XmlNode lastNode = null; XmlNode returnValue = null; using (ExecutorWrapper wrapper = new ExecutorWrapper("Coulda.Examples.dll", null, false)) returnValue = wrapper.RunClass("Coulda.Examples.FailingExample", node => { lastNode = node; return true; }); XmlNode resultNode = ResultXmlUtility.GetResult(lastNode); ResultXmlUtility.AssertAttribute(resultNode, "name", "A test with an assertion should be able to fail"); ResultXmlUtility.AssertAttribute(resultNode, "type", "Coulda.Examples.FailingExample"); ResultXmlUtility.AssertAttribute(resultNode, "method", "A_failing_example"); ResultXmlUtility.AssertAttribute(resultNode, "result", "Fail"); } }
public void CanCancelBetweenTestMethodRuns() { string code = @" using Xunit; public class TestClass { [Fact] public void TestMethod1() { } [Fact] public void TestMethod2() { } }"; using (MockAssembly assembly = new MockAssembly()) { assembly.Compile(code); XmlNode lastNode = null; using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false)) wrapper.RunClass("TestClass", node => { lastNode = node; return false; }); Assert.Equal(0, lastNode.ChildNodes.Count); // Cancels from the start of the first test } }
public void InvalidClassName() { 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.RunClass("TestClassIsNotMe", null)); } }
public void ClassWhichHasNoTests() { string code = @" using Xunit; public class PlainOldDotNetClass { }"; using (MockAssembly assembly = new MockAssembly()) { assembly.Compile(code); XmlNode lastNode = null; using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false)) wrapper.RunClass("PlainOldDotNetClass", node => { lastNode = node; return true; }); Assert.Equal("class", lastNode.Name); Assert.Equal(0, lastNode.ChildNodes.Count); // Empty class node } }
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.RunClass("TestClass", node => { lastNode = node; return true; }); XmlNode resultNode = ResultXmlUtility.GetResult(lastNode); Assert.Equal("Pass", resultNode.Attributes["result"].Value); Assert.Equal(returnValue, lastNode); } }