protected override UnitTestResult OnRun(TestContext testContext)
        {
            UnitTestResult tres = new UnitTestResult();

            OnBeginTest(testContext);

            try {
                foreach (UnitTest t in Tests)
                {
                    UnitTestResult res;
                    try {
                        res = OnRunChildTest(t, testContext);
                        if (testContext.Monitor.IsCancelRequested)
                        {
                            break;
                        }
                    } catch (Exception ex) {
                        res = UnitTestResult.CreateFailure(ex);
                    }
                    tres.Add(res);
                }
            } finally {
                OnEndTest(testContext);
            }
            return(tres);
        }
Exemple #2
0
        public UnitTestResult Run(TestContext testContext)
        {
            testContext.Monitor.BeginTest(this);
            UnitTestResult res = null;
            object         ctx = testContext.ContextData;

            try {
                Status = TestStatus.Running;
                res    = OnRun(testContext);
            } catch (global::NUnit.Framework.SuccessException) {
                res = UnitTestResult.CreateSuccess();
            } catch (global::NUnit.Framework.IgnoreException ex) {
                res = UnitTestResult.CreateIgnored(ex.Message);
            } catch (global::NUnit.Framework.InconclusiveException ex) {
                res = UnitTestResult.CreateInconclusive(ex.Message);
            } catch (Exception ex) {
                res = UnitTestResult.CreateFailure(ex);
            } finally {
                Status = TestStatus.Ready;
                testContext.Monitor.EndTest(this, res);
            }
            RegisterResult(testContext, res);
            testContext.ContextData = ctx;
            return(res);
        }
Exemple #3
0
        void RuntimeErrorCleanup(TestContext testContext, UnitTest t, Exception ex)
        {
            UnitTestResult result = UnitTestResult.CreateFailure(ex);

            t.RegisterResult(testContext, result);
            while (t != null && t != this)
            {
                testContext.Monitor.EndTest(t, result);
                t.Status = TestStatus.Ready;
                t        = t.Parent;
            }
        }
Exemple #4
0
        public UnitTestResult Run(TestContext testContext)
        {
            testContext.Monitor.BeginTest(this);
            UnitTestResult res = null;
            object         ctx = testContext.ContextData;

            try {
                Status = TestStatus.Running;
                res    = OnRun(testContext);
            } catch (Exception ex) {
                res = UnitTestResult.CreateFailure(ex);
            } finally {
                Status = TestStatus.Ready;
                testContext.Monitor.EndTest(this, res);
            }
            RegisterResult(testContext, res);
            testContext.ContextData = ctx;
            return(res);
        }
Exemple #5
0
        internal UnitTestResult RunUnitTest(UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
        {
            var runnerExe = GetCustomConsoleRunnerCommand();

            if (runnerExe != null)
            {
                return(RunWithConsoleRunner(runnerExe, test, suiteName, pathName, testName, testContext));
            }

            ExternalTestRunner runner       = (ExternalTestRunner)Runtime.ProcessService.CreateExternalProcessObject(typeof(ExternalTestRunner), testContext.ExecutionContext, UserAssemblyPaths);
            LocalTestMonitor   localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null);

            ITestFilter filter = null;

            if (test != null)
            {
                if (test is UnitTestGroup)
                {
                    filter = new TestNameFilter(CollectTests((UnitTestGroup)test));
                }
                else
                {
                    filter = new TestNameFilter(test.TestId);
                }
            }
            else
            {
                NUnitCategoryOptions categoryOptions = (NUnitCategoryOptions)test.GetOptions(typeof(NUnitCategoryOptions));
                if (categoryOptions.EnableFilter && categoryOptions.Categories.Count > 0)
                {
                    string[] cats = new string [categoryOptions.Categories.Count];
                    categoryOptions.Categories.CopyTo(cats, 0);
                    filter = new CategoryFilter(cats);
                    if (categoryOptions.Exclude)
                    {
                        filter = new NotFilter(filter);
                    }
                }
            }

            RunData rd = new RunData();

            rd.Runner       = runner;
            rd.Test         = this;
            rd.LocalMonitor = localMonitor;
            testContext.Monitor.CancelRequested += new TestHandler(rd.Cancel);

            UnitTestResult result;

            try {
                if (string.IsNullOrEmpty(AssemblyPath))
                {
                    string msg = GettextCatalog.GetString("Could not get a valid path to the assembly. There may be a conflict in the project configurations.");
                    throw new Exception(msg);
                }
                System.Runtime.Remoting.RemotingServices.Marshal(localMonitor, null, typeof(IRemoteEventListener));

                string testRunnerAssembly, testRunnerType;
                GetCustomTestRunner(out testRunnerAssembly, out testRunnerType);

                result = runner.Run(localMonitor, filter, AssemblyPath, "", new List <string> (SupportAssemblies), testRunnerType, testRunnerAssembly);
                if (testName != null)
                {
                    result = localMonitor.SingleTestResult;
                }
            } catch (Exception ex) {
                if (!localMonitor.Canceled)
                {
                    LoggingService.LogError(ex.ToString());
                    if (localMonitor.RunningTest != null)
                    {
                        RuntimeErrorCleanup(testContext, localMonitor.RunningTest, ex);
                    }
                    else
                    {
                        testContext.Monitor.ReportRuntimeError(null, ex);
                        throw;
                    }
                    result = UnitTestResult.CreateFailure(ex);
                }
                else
                {
                    result = UnitTestResult.CreateFailure(GettextCatalog.GetString("Canceled"), null);
                }
            } finally {
                testContext.Monitor.CancelRequested -= new TestHandler(rd.Cancel);
                runner.Dispose();
                System.Runtime.Remoting.RemotingServices.Disconnect(localMonitor);
            }

            return(result);
        }
        internal UnitTestResult RunUnitTest(UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
        {
            var runnerExe = GetCustomConsoleRunnerCommand();

            if (runnerExe != null)
            {
                return(RunWithConsoleRunner(runnerExe, test, suiteName, pathName, testName, testContext));
            }
            var console = IdeApp.Workbench?.ProgressMonitors.ConsoleFactory.CreateConsole();
            ExternalTestRunner runner       = (ExternalTestRunner)Runtime.ProcessService.CreateExternalProcessObject(typeof(ExternalTestRunner), testContext.ExecutionContext, UserAssemblyPaths, console);
            LocalTestMonitor   localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null);

            ITestFilter filter = null;

            if (test != null)
            {
                if (test is UnitTestGroup)
                {
                    filter = new TestNameFilter(CollectTests((UnitTestGroup)test));
                }
                else
                {
                    filter = new TestNameFilter(test.TestId);
                }
            }

            RunData rd = new RunData();

            rd.Runner       = runner;
            rd.Test         = this;
            rd.LocalMonitor = localMonitor;
            testContext.Monitor.CancelRequested += new TestHandler(rd.Cancel);

            UnitTestResult result;
            var            crashLogFile = Path.GetTempFileName();

            try {
                if (string.IsNullOrEmpty(AssemblyPath))
                {
                    string msg = GettextCatalog.GetString("Could not get a valid path to the assembly. There may be a conflict in the project configurations.");
                    throw new Exception(msg);
                }
                System.Runtime.Remoting.RemotingServices.Marshal(localMonitor, null, typeof(IRemoteEventListener));

                string testRunnerAssembly, testRunnerType;
                GetCustomTestRunner(out testRunnerAssembly, out testRunnerType);

                result = runner.Run(localMonitor, filter, AssemblyPath, "", new List <string> (SupportAssemblies), testRunnerType, testRunnerAssembly, crashLogFile);
                if (testName != null)
                {
                    result = localMonitor.SingleTestResult;
                }

                ReportCrash(testContext, crashLogFile);
            } catch (Exception ex) {
                if (ReportCrash(testContext, crashLogFile))
                {
                    result = UnitTestResult.CreateFailure(GettextCatalog.GetString("Unhandled exception"), null);
                }
                else if (!localMonitor.Canceled)
                {
                    LoggingService.LogError(ex.ToString());
                    if (localMonitor.RunningTest != null)
                    {
                        RuntimeErrorCleanup(testContext, localMonitor.RunningTest, ex);
                    }
                    else
                    {
                        testContext.Monitor.ReportRuntimeError(null, ex);
                        throw;
                    }
                    result = UnitTestResult.CreateFailure(ex);
                }
                else
                {
                    result = UnitTestResult.CreateFailure(GettextCatalog.GetString("Canceled"), null);
                }
            } finally {
                File.Delete(crashLogFile);
                testContext.Monitor.CancelRequested -= new TestHandler(rd.Cancel);
                runner.Dispose();
                System.Runtime.Remoting.RemotingServices.Disconnect(localMonitor);
            }

            return(result);
        }