Exemplo n.º 1
0
        TestRunner SetupTest(IPNUnitServices services, TestConsoleAccess consoleAccess, TestLogInfo testLogInfo)
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(mNUnitAssemblyPath));

            TestPackage package = new TestPackage(Path.GetFileName(mNUnitAssemblyPath));

            TestRunner result = new SimpleTestRunner();

            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            bool testLoaded = result.Load(package);

            if (!testLoaded)
            {
                mLog.InfoFormat("Unable to locate test {0}", mPNUnitTestInfo.TestName);
                PNUnitTestResult testResult = PNUnitTestRunner.BuildError(
                    mPNUnitTestInfo, new Exception("Unable to locate tests"), consoleAccess,
                    testLogInfo);

                services.NotifyResult(
                    mPNUnitTestInfo.TestName, testResult);

                return(null);
            }

            InitPNUnitServices(
                mPNUnitTestInfo, result, services, consoleAccess, testLogInfo);

            return(result);
        }
Exemplo n.º 2
0
        public void Run(IPNUnitServices services)
        {
            try
            {
                TestResult result = null;

                TestRunner testRunner = null;

                TestConsoleAccess consoleAccess = new TestConsoleAccess(mPNUnitTestInfo.OutputFile);

                TestLogInfo testLogInfo = new TestLogInfo();

                try
                {
                    mLog.DebugFormat("Running test assembly {0}",
                                     mNUnitAssemblyPath);

                    ConsoleWriter outStream   = new ConsoleWriter(Console.Out);
                    ConsoleWriter errorStream = new ConsoleWriter(Console.Error);

                    testRunner = SetupTest(services, consoleAccess, testLogInfo);

                    if (testRunner == null)
                    {
                        return;
                    }

                    mLog.Debug("Running tests");

                    try
                    {
                        PNUnitServices.Get().InitBarriers();
                        PNUnitServices.Get().EnterBarrier(PNUnitServices.Get().GetTestStartBarrier());

                        result = RunNUnitAssembly(
                            services,
                            outStream,
                            testRunner,
                            Path.GetFileNameWithoutExtension(mPNUnitTestInfo.AssemblyName));

                        PNUnitServices.Get().EnterBarrier(PNUnitServices.Get().GetTestEndBarrier());
                    }
                    catch (Exception e)
                    {
                        mLog.ErrorFormat("Error running test {0}. {1}", mPNUnitTestInfo.TestName, e.Message);
                        mLog.Debug(e.StackTrace);

                        result = PNUnitTestRunner.BuildError(
                            mPNUnitTestInfo, e, consoleAccess, testLogInfo);
                    }
                }
                finally
                {
                    mLog.Info("Notifying the results");

                    PNUnitTestResult pnunitResult = PNUnitTestRunner.BuildResult(
                        mPNUnitTestInfo,
                        result, consoleAccess, testLogInfo);

                    mLog.Debug("Result built!! Now, notify the launcher ...");

                    try
                    {
                        services.NotifyResult(
                            mPNUnitTestInfo.TestName, pnunitResult);
                        mLog.Debug("<-Results NOTIFIED");
                    }
                    catch (Exception e)
                    {
                        mLog.ErrorFormat(
                            "Error notifying back the result of test {0}. {1}",
                            mPNUnitTestInfo.TestName, e.Message);
                        mLog.Error(
                            "If you're using a custom launcher.remoting.conf" +
                            " check that you've defined the binaryFormatter");
                    }

                    result = null;

                    UnloadTests(testRunner);
                }
            }
            catch (Exception ex)
            {
                mLog.ErrorFormat("Error running test {0} {1}",
                                 mPNUnitTestInfo.TestName, ex.Message);
                mLog.Debug(ex.StackTrace);
            }
        }