RunTest() public method

public RunTest ( string type, string method, Predicate callback ) : XmlNode
type string
method string
callback Predicate
return System.Xml.XmlNode
Beispiel #1
0
        /// <summary>
        /// Runs the specified test.
        /// </summary>
        /// <param name="className"></param>
        /// <param name="methodName"></param>
        /// <returns>True to indicate success, false to indicate fail</returns>
        public static bool RunExampleTest(string className, string methodName)
        {
            using (MockAssembly assembly = new MockAssembly())
            {

                XmlNode lastNode = null;
                XmlNode returnValue = null;

                using (ExecutorWrapper wrapper = new ExecutorWrapper("Coulda.Examples.dll", null, false))
                {
                    returnValue = wrapper.RunTest(className, methodName, node =>
                    {
                        lastNode = node;
                        return true;
                    });
                }
                XmlNode resultNode = ResultXmlUtility.GetResult(lastNode);
                //ResultXmlUtility.AssertAttribute(resultNode, "result", "Pass");
                if(resultNode.Attributes["result"].Value == "Pass")
                {
                    return true;
                }

            }
            return false;
        }
        /// <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);
        }
Beispiel #3
0
        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);
        }
        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
            }
        }
        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));
            }
        }
        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);
            }
        }
Beispiel #7
0
        static void Run(string className, System.Reflection.Assembly koanAssembly, ExecutorWrapper wrapper)
        {
            Type classToRun = koanAssembly.GetType(className);

            if (classToRun == null) { return; }

            string[] queue = new string[classToRun.GetMethods().Length + 1];
            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;
            }
            foreach (string test in queue)
            {
                if (String.IsNullOrEmpty(test)) { continue; }
                if (TEST_FAILED != 0) { continue; }
                wrapper.RunTest(className, test, callback);
            }
        }