コード例 #1
0
ファイル: PNUnitTestRunner.cs プロジェクト: scottwis/eddie
		private void ThreadProc()
		{
			PNUnitTestResult result = null;
			TestDomain testDomain = new TestDomain();

			try
			{
				log.InfoFormat("Thread entered for Test {0}:{1} Assembly {2}",
					mTestInfo.TestName, mTestInfo.TestToRun, mTestInfo.AssemblyName);
				ConsoleWriter outStream = new ConsoleWriter(Console.Out);

//				ConsoleWriter errorStream = new ConsoleWriter(Console.Error);                     
          
#if NUNIT_2_5
                ITest test = MakeTest(testDomain, Path.Combine(mConfig.PathToAssemblies, mTestInfo.AssemblyName));
#else
				testDomain.ShadowCopyFiles = false;

				Test test = MakeTest(testDomain, Path.Combine(mConfig.PathToAssemblies, mTestInfo.AssemblyName));
#endif

                if (test == null)
				{
					Console.Error.WriteLine("Unable to locate tests");
                
					mTestInfo.Services.NotifyResult(
						mTestInfo.TestName, null);
                
					return;
				}

				Directory.SetCurrentDirectory(mConfig.PathToAssemblies); // test directory ?
		
				EventListener collector = new EventCollector( outStream );

//				string savedDirectory = Environment.CurrentDirectory;

				log.Info("Creating PNUnitServices in the AppDomain of the test");
				object[] param = { mTestInfo, (ITestConsoleAccess)this }; 

				testDomain.AppDomain.CreateInstanceAndUnwrap(
					typeof(PNUnitServices).Assembly.FullName, 
					typeof(PNUnitServices).FullName,
					false, BindingFlags.Default, null, param, null, null, null);

				log.Info("Running tests");

				try
				{
#if NUNIT_2_5
                    TestFilter filter = new NUnit.Core.Filters.SimpleNameFilter(mTestInfo.TestToRun);
                    result = new PNUnitTestResult(testDomain.Run(collector, filter));
#else
                    result = new PNUnitTestResult(testDomain.Run(collector, new string[1] { mTestInfo.TestToRun })[0]);
#endif
                }
				catch( Exception e )
				{
					result = new PNUnitTestResult(e);
				}
                
			}
			finally
			{
				log.Info("Notifying the results");
				mTestInfo.Services.NotifyResult(
					mTestInfo.TestName, result);
				//Bug with framework
				if (IsWindows())
				{
					lock(obj)
					{
						log.Info("Unloading test appdomain");
						testDomain.Unload();
						log.Info("Unloaded test appdomain");
					}
				}
			}

		}
コード例 #2
0
ファイル: PNUnitTestRunner.cs プロジェクト: scottwis/eddie
			public EventCollector( ConsoleWriter writer )
			{
				debugger = Debugger.IsAttached;
				level = 0;
				this.writer = writer;
				this.currentTestName = string.Empty;
			}
コード例 #3
0
		private void CreateSummaryDocument(string xmlOutput, XmlTextReader transformReader,
						   ConsoleWriter outStream)
		{
			XPathDocument originalXPathDocument = new XPathDocument(new StringReader(xmlOutput));
			XslTransform summaryXslTransform = new XslTransform();
			
			// Using obsolete form for now, remove warning suppression from project after changing
			summaryXslTransform.Load(transformReader);
			
			// Using obsolete form for now, remove warning suppression from project after changing
			summaryXslTransform.Transform(originalXPathDocument,null,outStream);
		}
コード例 #4
0
        private void ThreadProc()
        {
            TestResult result = null;
            TestDomain testDomain = new TestDomain();

            TestConsoleAccess consoleAccess = new TestConsoleAccess();

            try
            {
                log.InfoFormat("Thread entered for Test {0}:{1} Assembly {2}",
                    mPNUnitTestInfo.TestName, mPNUnitTestInfo.TestToRun, mPNUnitTestInfo.AssemblyName);

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

                bool testLoaded = MakeTest(testDomain, Path.Combine(mConfig.PathToAssemblies, mPNUnitTestInfo.AssemblyName), GetShadowCopyCacheConfig());

                if (!testLoaded)
                {
                    log.InfoFormat("Unable to locate test {0}", mPNUnitTestInfo.TestName);
                    result = BuildError("Unable to locate tests", consoleAccess);

                    mPNUnitTestInfo.Services.NotifyResult(
                        mPNUnitTestInfo.TestName, result);

                    return;
                }

                Directory.SetCurrentDirectory(mConfig.PathToAssemblies); // test directory ?
                EventListener collector = new EventCollector( outStream );

                string savedDirectory = Environment.CurrentDirectory;

                log.Info("Creating PNUnitServices in the AppDomain of the test");

                object[] param = { mPNUnitTestInfo, (ITestConsoleAccess) consoleAccess };

                try
                {
                    System.Runtime.Remoting.ObjectHandle obj
            #if NET_2_0
                        = Activator.CreateInstance(
                            testDomain.AppDomain,
            #else

                        = testDomain.AppDomain.CreateInstance(
            #endif
                        typeof(PNUnitServices).Assembly.FullName,
                        typeof(PNUnitServices).FullName,
                        false, BindingFlags.Default, null, param, null, null, null);
                    obj.Unwrap();
                }
                catch( Exception e )
                {
                    result = BuildError(e, consoleAccess);
                    log.ErrorFormat("Error running test {0}", e.Message);
                    return;
                }

                log.Info("Running tests");

                try
                {
                    ITestFilter filter = new NUnit.Core.Filters.SimpleNameFilter(mPNUnitTestInfo.TestToRun);
                    result =
                        FindResult(
                            mPNUnitTestInfo.TestToRun,
                            testDomain.Run(collector, filter) );
                    filter = null;
                }
                catch( Exception e )
                {
                    result = BuildError(e, consoleAccess);
                    log.ErrorFormat("Error running test {0}", e.Message);
                }

            }
            finally
            {
                log.Info("Notifying the results");

                mPNUnitTestInfo.Services.NotifyResult(
                    mPNUnitTestInfo.TestName, BuildResult(result, consoleAccess));

                result = null;

                //Bug with framework
                if( IsWindows() )
                {
            #if !NET_2_0
                    lock(obj)
            #endif
                    {
                        testDomain.Unload();
                    }
                }
            }
        }
コード例 #5
0
        private void ThreadProc()
        {
            TestResult result = null;

            TestDomain testDomain = null;

            TestConsoleAccess consoleAccess = new TestConsoleAccess();

            try
            {
                log.DebugFormat("Thread entered for Test {0}:{1} Assembly {2}",
                    mPNUnitTestInfo.TestName,
                    mPNUnitTestInfo.TestToRun,
                    mPNUnitTestInfo.AssemblyName);

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

                testDomain = SetupTest(consoleAccess);

                if( testDomain == null )
                    return;

                log.Debug("Running tests");

                try
                {
                    if(mConfig.NoTimeout)
                    {
                        result = RunTest(outStream, testDomain);
                    }
                    else
                    {
                        RunTestWithTimeoutDelegate deleg = new RunTestWithTimeoutDelegate(
                            RunTest);
                        IAsyncResult ar = deleg.BeginInvoke(outStream, testDomain, null, new object());
                        if (!ar.AsyncWaitHandle.WaitOne(TEST_TIMEOUT, false))
                        {
                            testDomain.CancelRun();
                            throw new Exception("Test timeout exception");
                        }
                        else  
                        {
                            result = deleg.EndInvoke(ar);
                        }
                    }
                }
                catch( Exception e )
                {
                    result = BuildError(e, consoleAccess);
                    log.ErrorFormat("Error running test {0}", e.Message);
                }

            }
            finally
            {
                log.Info("Notifying the results");

                log.Debug("////////////////////////////////////////Notifying the results/////////////////////////");

                mPNUnitTestInfo.Services.NotifyResult(
                    mPNUnitTestInfo.TestName, BuildResult(result, consoleAccess, mPNUnitTestInfo));

                log.Debug("////////////////////////////////////////Results NOTIFIED/////////////////////////");
                result = null;

                ReleaseDomain(testDomain);
            }
        }
コード例 #6
0
        private TestResult RunTest(ConsoleWriter outStream, TestDomain testDomain)
        {
            EventListener collector = new EventCollector( outStream );

            ITestFilter filter = new NUnit.Core.Filters.SimpleNameFilter(mPNUnitTestInfo.TestToRun);
            TestResult result =
                FindResult(
                mPNUnitTestInfo.TestToRun,
                testDomain.Run(collector, filter, false, LoggingThreshold.Off) );
            return result;
        }