Example #1
0
        public static int RunTests(string[] args)
        {
            int      failures = 0;
            Assembly asm      = Assembly.GetCallingAssembly();

            // Test code as determined by args. if no args are specified then it runs all the tests.
            // The static method that is called is named "Test_<args[i]>", so if no method exists then no biggie.
            if (args.Length == 0) // Run all tests
            {
                foreach (Type type in asm.GetTypes())
                {
                    // Find and run types that implement TestClass interface
                    if (type.GetInterfaces().Contains(typeof(ITestClass)))
                    {
                        ITestClass tester = (ITestClass)Activator.CreateInstance(type);
                        int        failCount = 0, testCount = 0;
                        string     failMsg = tester.RunTests(ref failCount, ref testCount);
                        failures += failCount;
                    }
                }
            }
            else
            {
                foreach (string arg in args)
                {
                    foreach (Type type in asm.GetTypes())
                    {
                        string n = type.Name;
                        if (n.Length < arg.Length)
                        {
                            continue;
                        }
                        n = n.Substring(n.Length - arg.Length);
                        // Find and run types that implement TestClass interface, and name ends with args[i]
                        if (type.GetInterfaces().Contains(typeof(ITestClass)) && n.Equals(arg, StringComparison.InvariantCultureIgnoreCase))
                        {
                            ITestClass tester = (ITestClass)Activator.CreateInstance(type);
                            int        failCount = 0, testCount = 0;
                            string     failMsg = tester.RunTests(ref failCount, ref testCount);
                            failures += failCount;
                        }
                    }
                }
            }
            return(failures);
        }
Example #2
0
        private void runButton_Click(object sender, EventArgs e)
        {
            if (this.testCombo.SelectedItem == null)
            {
                return;
            }
            int  failCount = 0;
            int  testCount = 0;
            Type t         = testCombo.SelectedItem as Type;

            if (IsTestClass(t))
            {
                ITestClass itc = Activator.CreateInstance(t) as ITestClass;
                failMsgBox.Text = itc.RunTests(ref failCount, ref testCount);
            }
            else if (IsTestFixture(t))
            {
                failMsgBox.Text = RunNUnitTests(t, ref failCount, ref testCount);
            }
            failCountBox.Text = "Failed " + failCount + "/" + testCount;
        }