public RunTests ( string type, List |
||
type | string | |
methods | List |
|
callback | Predicate |
|
Результат |
public void TestMethodWithNonTestMethod() { string code = @" using Xunit; public class TestClass { [Fact] public void TestMethod1() {} [Fact] public void TestMethod2() {} [Fact] public void TestMethod3() {} public void NonTestMethod() {} }"; using (MockAssembly assembly = new MockAssembly()) { assembly.Compile(code); XmlNode lastNode = null; using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false)) wrapper.RunTests("TestClass", new List<string> { "TestMethod1", "NonTestMethod" }, node => { lastNode = node; return true; }); Assert.Single(lastNode.ChildNodes); // Only the test method XmlNode result = ResultXmlUtility.GetResult(lastNode, 0); Assert.Equal("Pass", result.Attributes["result"].Value); } }
public void NonPublicTestMethod() { string code = @" using Xunit; public class TestClass { [Fact] void NonPublicTestMethod() {} }"; using (MockAssembly assembly = new MockAssembly()) { assembly.Compile(code); XmlNode returnValue = null; using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false)) returnValue = wrapper.RunTests("TestClass", new List<string> { "NonPublicTestMethod" }, node => { return true; }); Assert.Single(returnValue.ChildNodes); XmlNode result = ResultXmlUtility.GetResult(returnValue, 0); Assert.Equal("Pass", result.Attributes["result"].Value); } }
public void CallbackIncludesStartMessages() { const string code = @" using Xunit; public class TestClass { [Fact] public void TestMethod1() {} [Fact] public void TestMethod2() {} [Fact] public void TestMethod3() {} }"; using (MockAssembly assembly = new MockAssembly()) { assembly.Compile(code); List<XmlNode> nodes = new List<XmlNode>(); using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false)) wrapper.RunTests("TestClass", new List<string> { "TestMethod1" }, node => { nodes.Add(node); return true; }); Assert.Equal(3, nodes.Count); Assert.Equal("start", nodes[0].Name); // <start> ResultXmlUtility.AssertAttribute(nodes[0], "name", "TestClass.TestMethod1"); ResultXmlUtility.AssertAttribute(nodes[0], "type", "TestClass"); ResultXmlUtility.AssertAttribute(nodes[0], "method", "TestMethod1"); Assert.Equal("test", nodes[1].Name); Assert.Equal("class", nodes[2].Name); } }
public void InvalidMethodName() { string code = @" using Xunit; public class TestClass { public void DummyMethod() {} }"; using (MockAssembly assembly = new MockAssembly()) { assembly.Compile(code); using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false)) Assert.Throws<ArgumentException>( () => wrapper.RunTests("TestClass", new List<string> { "DummyMethod", "DummyMethod2" }, null)); } }
public void AcceptanceTest() { string code = @" using Xunit; public class TestClass { [Fact] public void TestMethod1() {} [Fact] public void TestMethod2() {} [Fact] public void TestMethod3() {} }"; 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.RunTests("TestClass", new List<string> { "TestMethod1", "TestMethod2" }, node => { lastNode = node; return true; }); Assert.Equal(returnValue, lastNode); Assert.Equal(2, lastNode.ChildNodes.Count); // Two test results XmlNode result0 = ResultXmlUtility.GetResult(lastNode, 0); Assert.Equal("Pass", result0.Attributes["result"].Value); XmlNode result1 = ResultXmlUtility.GetResult(lastNode, 1); Assert.Equal("Pass", result1.Attributes["result"].Value); } }