コード例 #1
0
        private void CleanUpAfterTestRun()
        {
            // Restore the directory we saved
            if (currentDirectory != null)
            {
                Environment.CurrentDirectory = currentDirectory;
                currentDirectory             = null;
            }

            // Close our output buffers
            if (outBuffer != null)
            {
                outBuffer.Close();
                outBuffer = null;
            }

            if (errorBuffer != null)
            {
                errorBuffer.Close();
                errorBuffer = null;
            }

            // Restore previous console values
            if (saveOut != null)
            {
                Console.SetOut(saveOut);
                saveOut = null;
            }

            if (saveError != null)
            {
                Console.SetError(saveError);
                saveError = null;
            }
        }
コード例 #2
0
		private void CleanUpAfterTestRun()
		{
			// Restore the directory we saved
			if ( currentDirectory != null )
			{
				Environment.CurrentDirectory = currentDirectory;
				currentDirectory = null;
			}

			// Close our output buffers
			if ( outBuffer != null )
			{
				outBuffer.Close();
				outBuffer = null;
			}

			if ( errorBuffer != null )
			{
				errorBuffer.Close();
				errorBuffer = null;
			}

			// Restore previous console values
			if ( saveOut != null )
			{
				Console.SetOut( saveOut );
				saveOut = null;
			}

			if ( saveError != null )
			{
				Console.SetError( saveError );
				saveError = null;
			}
		}
コード例 #3
0
        /// <summary>
        /// Private method to run a set of tests. This routine is the workhorse
        /// that is called anytime tests are run.
        /// </summary>
        private TestResult[] Run(EventListener listener, Test[] tests)
        {
            // Create buffered writers for efficiency
            outBuffer   = new BufferedStringTextWriter(outText);
            errorBuffer = new BufferedStringTextWriter(errorText);

            // Save previous state of Console. This is needed because Console.Out and
            // Console.Error are static. In the case where the test itself calls this
            // method, we can lose output if we don't save and restore their values.
            // This is exactly what happens when we are testing NUnit itself.
            saveOut   = Console.Out;
            saveError = Console.Error;

            // Set Console to go to our buffers. Note that any changes made by
            // the user in the test code or the code it calls will defeat this.
            Console.SetOut(outBuffer);
            Console.SetError(errorBuffer);

            // Save the current directory so we can run each test in
            // the same directory as its assembly
            currentDirectory = Environment.CurrentDirectory;

            try
            {
                // Create an array for the resuls
                results = new TestResult[tests.Length];

                // Signal that we are starting the run
                this.listener = listener;
                listener.RunStarted(tests);

                // TODO: Get rid of count
                int count = 0;
                foreach (Test test in tests)
                {
                    count += filter == null?test.CountTestCases() : test.CountTestCases(filter);
                }

                events.FireRunStarting(tests, count);

                // Run each test, saving the results
                int index = 0;
                foreach (Test test in tests)
                {
                    string assemblyDirectory = Path.GetDirectoryName(this.assemblies[test.AssemblyKey]);

                    if (assemblyDirectory != null && assemblyDirectory != string.Empty)
                    {
                        Environment.CurrentDirectory = assemblyDirectory;
                    }

                    results[index++] = test.Run(this, filter);
                }

                // Signal that we are done
                listener.RunFinished(results);
                events.FireRunFinished(results);

                // Return result array
                return(results);
            }
            catch (Exception exception)
            {
                // Signal that we finished with an exception
                listener.RunFinished(exception);
                events.FireRunFinished(exception);
                // Rethrow - should we do this?
                throw;
            }
            finally
            {
                CleanUpAfterTestRun();
            }
        }
コード例 #4
0
		/// <summary>
		/// Private method to run a set of tests. This routine is the workhorse
		/// that is called anytime tests are run.
		/// </summary>
		private TestResult[] Run( EventListener listener, Test[] tests )
		{
			// Create buffered writers for efficiency
			outBuffer = new BufferedStringTextWriter( outText );
			errorBuffer = new BufferedStringTextWriter( errorText );

			// Save previous state of Console. This is needed because Console.Out and
			// Console.Error are static. In the case where the test itself calls this
			// method, we can lose output if we don't save and restore their values.
			// This is exactly what happens when we are testing NUnit itself.
			saveOut = Console.Out;
			saveError = Console.Error;

			// Set Console to go to our buffers. Note that any changes made by
			// the user in the test code or the code it calls will defeat this.
			Console.SetOut( outBuffer );
			Console.SetError( errorBuffer ); 

			// Save the current directory so we can run each test in
			// the same directory as its assembly
			currentDirectory = Environment.CurrentDirectory;
			
			try
			{
				// Create an array for the resuls
				results = new TestResult[ tests.Length ];

				// Signal that we are starting the run
				this.listener = listener;
				listener.RunStarted( tests );
				
				// TODO: Get rid of count
				int count = 0;
				foreach( Test test in tests )
					count += filter == null ? test.CountTestCases() : test.CountTestCases( filter );

				events.FireRunStarting( tests, count );
				
				// Run each test, saving the results
				int index = 0;
				foreach( Test test in tests )
				{
					string assemblyDirectory = Path.GetDirectoryName( this.assemblies[test.AssemblyKey] );

					if ( assemblyDirectory != null && assemblyDirectory != string.Empty )
						Environment.CurrentDirectory = assemblyDirectory;

					results[index++] = test.Run( this, filter );
				}

				// Signal that we are done
				listener.RunFinished( results );
				events.FireRunFinished( results );

				// Return result array
				return results;
			}
			catch( Exception exception )
			{
				// Signal that we finished with an exception
				listener.RunFinished( exception );
				events.FireRunFinished( exception );
				// Rethrow - should we do this?
				throw;
			}
			finally
			{
				CleanUpAfterTestRun();
			}
		}