Пример #1
0
        public PNUnitTestResult[] GetTestResults()
        {
            lock(mResultLock)
            {
                PNUnitTestResult[] result = new PNUnitTestResult[mResults.Count];
                int i = 0;
                foreach( PNUnitTestResult res in mResults )
                    result[i++] = res;

                return result;
            }
        }
Пример #2
0
 private static void PrintResult(int testNumber, PNUnitTestResult res)
 {
     Console.WriteLine(
         "({0})Name: {1}\n  Result: {2,-12} Assert Count: {3,-2} Time: {4,5}",
         testNumber,
         res.Name,
         res.IsSuccess ? "SUCCESS" : (res.IsFailure ? "FAILURE" : (! res.Executed ? "NOT EXECUTED": "UNKNOWN")),
         res.AssertCount,
         res.Time);
     if( !res.IsSuccess )
         Console.WriteLine("\nMessage: {0}\nStack Trace:\n{1}\n\n",
             res.Message, res.StackTrace);
 }
Пример #3
0
		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");
					}
				}
			}

		}
Пример #4
0
        private TestResult BuildError(Exception e, TestConsoleAccess consoleAccess)
        {
            TestName testName = new TestName();
            testName.Name = mPNUnitTestInfo.TestName;
            testName.FullName = mPNUnitTestInfo.TestName;
            testName.TestID = new TestID();

            TestResult result = new PNUnitTestResult(testName, consoleAccess.GetTestOutput());
            result.Error(e);
            return result;
        }
Пример #5
0
        private TestResult BuildError(string message, TestConsoleAccess consoleAccess)
        {
            TestName testName = new TestName();
            testName.Name = mPNUnitTestInfo.TestName;
            testName.FullName = mPNUnitTestInfo.TestName;
            testName.TestID = new TestID();

            TestResult result = new PNUnitTestResult(testName, consoleAccess.GetTestOutput());
            result.Failure(message, string.Empty);
            return result;
        }
Пример #6
0
        public void NotifyResult(string TestName, PNUnitTestResult result)
        {
            log.DebugFormat("NotifyResult called for TestGroup {0}, Test {1}",
                mTestGroup.Name, TestName);
            lock(mResultLock)
            {
                log.DebugFormat("NotifyResult lock entered for TestGroup {0}, Test {1}",
                    mTestGroup.Name, TestName);

                mResults.Add(result);
                if( mResults.Count == mLaunchedTests )
                {
                    log.DebugFormat("All the tests notified the results, waking up. mResults.Count == {0}",
                        mResults.Count);
                    mFinish.Set();
                }

            }
            lock( mBarriers )
            {
                if( mBarriersOfTests.Contains(TestName) )
                {
                    log.DebugFormat("Going to abandon barriers of test {0}", TestName);
                    IList list = (IList) mBarriersOfTests[TestName];
                    foreach( string barrier in list )
                    {
                        log.DebugFormat("Abandoning barrier {0}", barrier);
                        ((Barrier)mBarriers[barrier]).Abandon();
                    }
                }
            }
            log.DebugFormat("NotifyResult finishing for TestGroup {0}, Test {1}.",
                mTestGroup.Name, TestName);
            log.InfoFormat("Result for TestGroup {0}, Test {1}: {2}",
                mTestGroup.Name, TestName, result.IsSuccess ? "PASS" : "FAIL");
        }
Пример #7
0
        private void NotifyException(TestConf test, Exception e)
        {
            TestName tn = new TestName();
            tn.Name = test.Name;

            PNUnitTestResult tr = new PNUnitTestResult(tn, e.Message);
            tr.Failure(e.Message, e.StackTrace);

            NotifyResult(test.Name, tr);
        }
Пример #8
0
        private TestResult BuildResult(
            TestResult result,
            TestConsoleAccess consoleAccess,
            PNUnitTestInfo testInfo)
        {
            //the test namespace contains errors
            if( result == null )
            {
                TestName testName = new TestName();
                testName.Name = testInfo.TestName;

                string errormsg = "The test {0} couldn't be found in the assembly {1}";

                result = new PNUnitTestResult(testName, string.Empty);
                result.Failure(
                    string.Format(errormsg, testInfo.TestToRun, testInfo.AssemblyName),
                    string.Empty);

                return result;
            }

            if( !result.IsSuccess /*|| ReturnTestOutput()*/ )
                return new PNUnitTestResult(result, consoleAccess.GetTestOutput());
            else
                return result;
        }