Esempio n. 1
0
        /// <summary>
        /// Unload the current test suite and fire the Unloaded event
        /// </summary>
        public void UnloadTest( )
        {
            if (IsTestLoaded)
            {
                // Hold the name for notifications after unload
                string fileName = TestFileName;

                try
                {
                    events.FireTestUnloading(TestFileName, this.loadedTest);

                    RemoveWatcher();

                    testDomain.Unload();

                    testDomain = null;

                    loadedTest     = null;
                    loadedTestName = null;
                    results        = null;
                    reloadPending  = false;

                    events.FireTestUnloaded(fileName, this.loadedTest);
                }
                catch (Exception exception)
                {
                    lastException = exception;
                    events.FireTestUnloadFailed(fileName, exception);
                }
            }
        }
Esempio n. 2
0
        private static bool MakeTestFromCommandLine(TestDomain testDomain,
						string testDll)
        {
            ServiceManager.Services.AddService(new DomainManager());
              var package = new TestPackage(testDll);
              return testDomain.Load(package);
        }
        public override bool Load(TestPackage package)
        {
            this.projectName       = package.FullName;
            this.testName.FullName = this.testName.Name = projectName;
            runners = new ArrayList();

            int nfound = 0;
            int index  = 0;

            string targetAssemblyName = null;

            if (package.TestName != null && package.Assemblies.Contains(package.TestName))
            {
                targetAssemblyName = package.TestName;
                package.TestName   = null;
            }

            foreach (string assembly in package.Assemblies)
            {
                if (targetAssemblyName == null || targetAssemblyName == assembly)
                {
                    TestDomain runner = new TestDomain(this.runnerID * 100 + index + 1);

                    TestPackage p = new TestPackage(assembly);
                    p.AutoBinPath       = package.AutoBinPath;
                    p.ConfigurationFile = package.ConfigurationFile;
                    p.BasePath          = package.BasePath;
                    p.PrivateBinPath    = package.PrivateBinPath;
                    p.TestName          = package.TestName;
                    foreach (object key in package.Settings.Keys)
                    {
                        p.Settings[key] = package.Settings[key];
                    }

                    if (package.TestName == null)
                    {
                        runners.Add(runner);
                        if (runner.Load(p))
                        {
                            nfound++;
                        }
                    }
                    else if (runner.Load(p))
                    {
                        runners.Add(runner);
                        nfound++;
                    }
                }
            }

            if (package.TestName == null && targetAssemblyName == null)
            {
                return(nfound == package.Assemblies.Count);
            }
            else
            {
                return(nfound > 0);
            }
        }
Esempio n. 4
0
		private void CreateRunners( int count )
		{
			runners = new ArrayList();
			for( int index = 0; index < count; index++ )
			{
				TestDomain runner = new TestDomain( this.runnerID * 100 + index + 1 );
				runners.Add( runner );
			}
		}
Esempio n. 5
0
        public void LoadTest(string testName)
        {
            try
            {
                events.FireTestLoading(TestFileName);

                testDomain = new TestDomain(stdOutWriter, stdErrWriter);
                Test test = testDomain.Load(TestProject, testName);

                TestSuite suite = test as TestSuite;
                if (suite != null)
                {
                    suite.Sort();
                }

                loadedTest     = test;
                loadedTestName = testName;
                results        = null;
                reloadPending  = false;

                if (ReloadOnChange)
                {
                    InstallWatcher( );
                }

                if (suite != null)
                {
                    events.FireTestLoaded(TestFileName, this.loadedTest);
                }
                else
                {
                    lastException = new ApplicationException(string.Format("Unable to find test {0} in assembly", testName));
                    events.FireTestLoadFailed(TestFileName, lastException);
                }
            }
            catch (FileNotFoundException exception)
            {
                lastException = exception;

                foreach (string assembly in TestProject.ActiveConfig.AbsolutePaths)
                {
                    if (Path.GetFileNameWithoutExtension(assembly) == exception.FileName &&
                        !ProjectPath.SamePathOrUnder(testProject.ActiveConfig.BasePath, assembly))
                    {
                        lastException = new ApplicationException(string.Format("Unable to load {0} because it is not located under the AppBase", exception.FileName), exception);
                        break;
                    }
                }

                events.FireTestLoadFailed(TestFileName, lastException);
            }
            catch (Exception exception)
            {
                lastException = exception;
                events.FireTestLoadFailed(TestFileName, exception);
            }
        }
 private void CreateRunners(int count)
 {
     runners = new ArrayList();
     for (int index = 0; index < count; index++)
     {
         TestDomain runner = new TestDomain(this.runnerID * 100 + index + 1);
         runners.Add(runner);
     }
 }
Esempio n. 7
0
 private void CreateRunners( int count )
 {
     runners = new TestRunner[count];
     for( int index = 0; index < count; index++ )
     {
         TestDomain runner = new TestDomain( this.runnerID * 100 + index + 1 );
         runners[index] = runner;
     }
 }
Esempio n. 8
0
 private void CreateRunners(int count)
 {
     runners = new TestRunner[count];
     for (int index = 0; index < count; index++)
     {
         TestDomain runner = new TestDomain(this.runnerID * 100 + index + 1);
         runners[index] = runner;
     }
 }
        public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink)
        {
            testLog.Initialize(messageLogger);
            Info("discovering tests", "started");

            // Ensure any channels registered by other adapters are unregistered
            CleanUpRegisteredChannels();

            foreach (string sourceAssembly in sources)
            {
                testLog.SendDebugMessage("Processing " + sourceAssembly);

                TestRunner runner = new TestDomain();
                TestPackage package = new TestPackage(sourceAssembly);
                TestConverter testConverter = null;
                try
                {
                    if (runner.Load(package))
                    {
                        testConverter  = new TestConverter(testLog, sourceAssembly);
                        int cases = ProcessTestCases(runner.Test, discoverySink, testConverter);
                        testLog.SendDebugMessage(string.Format("Discovered {0} test cases", cases));
                        }
                    else
                    {
                        testLog.NUnitLoadError(sourceAssembly);
                    }
                }
                catch (System.BadImageFormatException)
                {
                    // we skip the native c++ binaries that we don't support.
                    testLog.AssemblyNotSupportedWarning(sourceAssembly);
                }

                catch (System.IO.FileNotFoundException ex)
                {
                    // Probably from the GetExportedTypes in NUnit.core, attempting to find an assembly, not a problem if it is not NUnit here
                    testLog.DependentAssemblyNotFoundWarning(ex.FileName, sourceAssembly);
                }
                catch (System.Exception ex)
                {
                    testLog.SendErrorMessage("Exception thrown discovering tests in " + sourceAssembly, ex);
                }
                finally
                {
                    if (testConverter != null)
                        testConverter.Dispose();
                    testConverter = null;
                    runner.Unload();
                }
            }

            Info("discovering test", "finished");
        }
Esempio n. 10
0
		public override bool Load(TestPackage package)
		{
			this.projectName = package.FullName;
			this.testName.FullName = this.testName.Name = projectName;
			runners = new ArrayList();

			int nfound = 0;
			int index = 0;

			string targetAssemblyName = null;
			if( package.TestName != null && package.Assemblies.Contains( package.TestName ) )
			{
				targetAssemblyName = package.TestName;
				package.TestName = null;
			}
			
			foreach( string assembly in package.Assemblies )
			{
				if ( targetAssemblyName == null || targetAssemblyName == assembly )
				{
					TestDomain runner = new TestDomain( this.runnerID * 100 + index + 1 );

					TestPackage p = new TestPackage( assembly );
					p.AutoBinPath = package.AutoBinPath;
					p.ConfigurationFile = package.ConfigurationFile;
					p.BasePath = package.BasePath;
					p.PrivateBinPath = package.PrivateBinPath;
					p.TestName = package.TestName;
					foreach( object key in package.Settings.Keys )
						p.Settings[key] = package.Settings[key];

					if ( package.TestName == null )
					{
						runners.Add( runner );
						if ( runner.Load( p ) )
							nfound++;
					}
					else if ( runner.Load( p ) )
					{
						runners.Add( runner );
						nfound++;
					}
				}
			}

			if ( package.TestName == null && targetAssemblyName == null )
				return nfound == package.Assemblies.Count;
			else
				return nfound > 0;
		}
Esempio n. 11
0
        /// <summary>
        /// Handle watcher event that signals when the loaded assembly
        /// file has changed. Make sure it's a real change before
        /// firing the SuiteChangedEvent. Since this all happens
        /// asynchronously, we use an event to let ui components
        /// know that the failure happened.
        /// </summary>
        /// <param name="assemblyFileName">Assembly file that changed</param>
        public void OnTestChanged(string testFileName)
        {
            if (IsTestRunning)
            {
                reloadPending = true;
            }
            else
            {
                try
                {
                    events.FireTestReloading(testFileName, this.loadedTest);

                    // Don't unload the old domain till after the event
                    // handlers get a chance to compare the trees.
                    TestDomain newDomain = new TestDomain(stdOutWriter, stdErrWriter);
                    Test       newTest   = newDomain.Load(testProject, loadedTestName);
                    TestSuite  suite     = newTest as TestSuite;
                    if (suite != null)
                    {
                        suite.Sort();
                    }

                    testDomain.Unload();

                    testDomain    = newDomain;
                    loadedTest    = newTest;
                    reloadPending = false;

                    events.FireTestReloaded(testFileName, newTest);
                }
                catch (Exception exception)
                {
                    lastException = exception;
                    events.FireTestReloadFailed(testFileName, exception);
                }
            }
        }
Esempio n. 12
0
		private static Test MakeTestFromCommandLine(TestDomain testDomain, ConsoleOptions parser)
		{
			NUnitProject project;

			if ( parser.IsTestProject )
			{
				project = NUnitProject.LoadProject( (string)parser.Parameters[0] );
				string configName = (string) parser.config;
				if ( configName != null )
					project.SetActiveConfig( configName );
			}
			else
				project = NUnitProject.FromAssemblies( (string[])parser.Parameters.ToArray( typeof( string ) ) );

			return testDomain.Load( project, parser.fixture );
		}
Esempio n. 13
0
        private TestDomain SetupTest(TestConsoleAccess consoleAccess)
        {
            try
            {
                TestDomain result;

                lock( mFreeDomains.SyncRoot )
                {
                    log.Debug(">Locking mFreeDomains.SyncRoot");

                    if( mbUseDomainPool && mFreeDomains.Count > 0 )
                    {
                        log.Debug("Reusing a previously created TestDomain");
                        result = mFreeDomains.Dequeue() as TestDomain;
                        CreatePNUnitServices(result, consoleAccess);
                        return result;
                    }

                    log.Debug("Creating a new TestDomain");
                    result = new TestDomain();

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

                    log.Debug("MakeTest executed");

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

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

                        return null;
                    }

                    log.Debug("Test loaded, going to set CurrentDirectory");

                    Directory.SetCurrentDirectory(mConfig.PathToAssemblies); // test directory ?

                    log.Debug("Creating PNUnit services");

                    CreatePNUnitServices(result, consoleAccess);

                    return result;
                }
            }
            finally
            {
                log.Debug("<Unlocking mFreeDomains.SyncRoot");
            }
        }
Esempio n. 14
0
        private void CreatePNUnitServices(
            TestDomain testDomain,
            TestConsoleAccess consoleAccess)
        {
            log.Info("Creating PNUnitServices in the AppDomain of the test");

            object[] param = { mPNUnitTestInfo, 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 )
            {
                BuildError(e, consoleAccess);
                log.ErrorFormat("Error running test {0}", e.Message);
                return;
            }
        }
Esempio n. 15
0
        public void LoadTestsFromCompiledAssembly()
        {
            CompilerResults results = compiler.CompileCode( goodCode );
            Assert.AreEqual( 0, results.NativeCompilerReturnValue );

            TestRunner runner = new TestDomain();

            try
            {
                Assert.IsTrue( runner.Load( new TestPackage( outputName ) ) );
                Assert.AreEqual( 2, runner.Test.TestCount );
            }
            finally
            {
                runner.Unload();
            }
        }
Esempio n. 16
0
		public void LoadTest( string testName )
		{
			try
			{
				events.FireTestLoading( TestFileName );

				testDomain = new TestDomain( stdOutWriter, stdErrWriter );		
				Test test = testDomain.Load( TestProject, testName );

				TestSuite suite = test as TestSuite;
				if ( suite != null )
					suite.Sort();
			
				loadedTest = test;
				loadedTestName = testName;
				results = null;
				reloadPending = false;
			
				if ( ReloadOnChange )
					InstallWatcher( );

				if ( suite != null )
					events.FireTestLoaded( TestFileName, this.loadedTest );
				else
				{
					lastException = new ApplicationException( string.Format ( "Unable to find test {0} in assembly", testName ) );
					events.FireTestLoadFailed( TestFileName, lastException );
				}
			}
			catch( FileNotFoundException exception )
			{
				lastException = exception;

				foreach( string assembly in TestProject.ActiveConfig.AbsolutePaths )
				{
					if ( Path.GetFileNameWithoutExtension( assembly ) == exception.FileName &&
						!ProjectPath.SamePathOrUnder( testProject.ActiveConfig.BasePath, assembly ) )
					{
						lastException = new ApplicationException( string.Format( "Unable to load {0} because it is not located under the AppBase", exception.FileName ), exception );
						break;
					}
				}

				events.FireTestLoadFailed( TestFileName, lastException );
			}
			catch( Exception exception )
			{
				lastException = exception;
				events.FireTestLoadFailed( TestFileName, exception );
			}
		}
Esempio n. 17
0
		/// <summary>
		/// Handle watcher event that signals when the loaded assembly
		/// file has changed. Make sure it's a real change before
		/// firing the SuiteChangedEvent. Since this all happens
		/// asynchronously, we use an event to let ui components
		/// know that the failure happened.
		/// </summary>
		/// <param name="assemblyFileName">Assembly file that changed</param>
		public void OnTestChanged( string testFileName )
		{
			if ( IsTestRunning )
				reloadPending = true;
			else 
				try
				{
					events.FireTestReloading( testFileName, this.loadedTest );

					// Don't unload the old domain till after the event
					// handlers get a chance to compare the trees.
					TestDomain newDomain = new TestDomain( stdOutWriter, stdErrWriter );
					Test newTest = newDomain.Load( testProject, loadedTestName );
					TestSuite suite = newTest as TestSuite;
					if ( suite != null )
						suite.Sort();

					testDomain.Unload();

					testDomain = newDomain;
					loadedTest = newTest;
					reloadPending = false;

					events.FireTestReloaded( testFileName, newTest );				
				}
				catch( Exception exception )
				{
					lastException = exception;
					events.FireTestReloadFailed( testFileName, exception );
				}
		}
Esempio n. 18
0
		/// <summary>
		/// Unload the current test suite and fire the Unloaded event
		/// </summary>
		public void UnloadTest( )
		{
			if( IsTestLoaded )
			{
				// Hold the name for notifications after unload
				string fileName = TestFileName;

				try
				{
					events.FireTestUnloading( TestFileName, this.loadedTest );

					RemoveWatcher();

					testDomain.Unload();

					testDomain = null;

					loadedTest = null;
					loadedTestName = null;
					results = null;
					reloadPending = false;

					events.FireTestUnloaded( fileName, this.loadedTest );
				}
				catch( Exception exception )
				{
					lastException = exception;
					events.FireTestUnloadFailed( fileName, exception );
				}
			}
		}
Esempio n. 19
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();
                    }
                }
            }
        }
Esempio n. 20
0
 public UnitTester()
 {
     _testDomain = new TestDomain();
       _testRunner = _testDomain;
 }
Esempio n. 21
0
        private void ReleaseDomain(TestDomain testDomain)
        {
#if !NET_2_0
            lock(obj)
#endif
            {
                lock( mFreeDomains.SyncRoot )
                {
                    log.Debug("************************ RELEASING A TESTDOMAIN ************************************");
                    if( mbUseDomainPool )
                    {
                        mFreeDomains.Enqueue(testDomain);
                    }
                    else
                    {
                        testDomain.Unload();
                    }
                }
            }
        }
Esempio n. 22
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");
					}
				}
			}

		}
Esempio n. 23
0
        private ITest MakeTest(TestDomain testDomain, string assemblyName)
        {
            TestPackage package = new TestPackage(assemblyName);
            package.Settings["ShadowCopyFiles"] = false;

            return testDomain.Load(package) ? testDomain.Test : null;
        }
        public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink)
        {
            TestLog.Initialize(messageLogger);
            if (RegistryFailure)
            {
                TestLog.SendErrorMessage(ErrorMsg);
            }
            Info("discovering tests", "started");

            // Ensure any channels registered by other adapters are unregistered
            CleanUpRegisteredChannels();

            // var initPath = Path.Combine(Environment.CurrentDirectory, "init.tml");

            var initPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NUnitTestAdapter");
            initPath = Path.Combine(initPath, "init.tml");

            var blackList = new List<string>();
            if (File.Exists(initPath))
            {
                var config = Toml.ReadFile<Configuration>(initPath);
                blackList = config.Blacklist.Select(b => b.ToLowerInvariant()).ToList();
            }
           

            foreach (string sourceAssembly in sources)
            {
                if (blackList.Contains(Path.GetFileName(sourceAssembly.ToLowerInvariant())))
                {
                    TestLog.SendDebugMessage("Ignore " + sourceAssembly);
                    continue;
                }

                TestLog.SendDebugMessage("Processing " + sourceAssembly);

                //config.Blacklist.Add(sourceAssembly);

                TestRunner runner = new TestDomain();
                var package = CreateTestPackage(sourceAssembly);
                TestConverter testConverter = null;
                try
                {
                    if (runner.Load(package))
                    {
                        testConverter = new TestConverter(TestLog, sourceAssembly);
                        int cases = ProcessTestCases(runner.Test, discoverySink, testConverter);
                        TestLog.SendDebugMessage(string.Format("Discovered {0} test cases", cases));
                    }
                    else
                    {
                        TestLog.NUnitLoadError(sourceAssembly);
                    }
                }
                catch (BadImageFormatException)
                {
                    // we skip the native c++ binaries that we don't support.
                    TestLog.AssemblyNotSupportedWarning(sourceAssembly);
                }

                catch (FileNotFoundException ex)
                {
                    // Probably from the GetExportedTypes in NUnit.core, attempting to find an assembly, not a problem if it is not NUnit here
                    TestLog.DependentAssemblyNotFoundWarning(ex.FileName, sourceAssembly);
                }
                catch (FileLoadException ex)
                {
                    // Attempts to load an invalid assembly, or an assembly with missing dependencies
                    TestLog.LoadingAssemblyFailedWarning(ex.FileName, sourceAssembly);
                }
                catch (UnsupportedFrameworkException ex)
                {
                    TestLog.UnsupportedFrameworkWarning(sourceAssembly);
                }
                catch (Exception ex)
                {

                    TestLog.SendErrorMessage("Exception thrown discovering tests in " + sourceAssembly, ex);
                }
                finally
                {
                    if (testConverter != null)
                        testConverter.Dispose();
                    runner.Unload();
                }
            }

            //Toml.WriteFile(config, @"test.tml");

            Info("discovering test", "finished");
        }
        public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink)
        {
            TestLog.Initialize(messageLogger);
            if (RegistryFailure)
            {
                TestLog.SendErrorMessage(ErrorMsg);
            }
            Info("discovering tests", "started");

            // Ensure any channels registered by other adapters are unregistered
            CleanUpRegisteredChannels();

            foreach (string sourceAssembly in sources)
            {
                TestLog.SendDebugMessage("Processing " + sourceAssembly);

                TestRunner runner = new TestDomain();
                var package = CreateTestPackage(sourceAssembly);
                TestConverter testConverter = null;
                try
                {
                    if (runner.Load(package))
                    {
                        testConverter = new TestConverter(TestLog, sourceAssembly);
                        int cases = ProcessTestCases(runner.Test, discoverySink, testConverter);
                        TestLog.SendDebugMessage(string.Format("Discovered {0} test cases", cases));
                    }
                    else
                    {
                        TestLog.NoNUnit2TestsFoundIn(sourceAssembly);
                    }
                }
                catch (BadImageFormatException)
                {
                    // we skip the native c++ binaries that we don't support.
                    TestLog.AssemblyNotSupportedWarning(sourceAssembly);
                }

                catch (FileNotFoundException ex)
                {
                    // Probably from the GetExportedTypes in NUnit.core, attempting to find an assembly, not a problem if it is not NUnit here
                    TestLog.DependentAssemblyNotFoundWarning(ex.FileName, sourceAssembly);
                }
                catch (FileLoadException ex)
                {
                    // Attempts to load an invalid assembly, or an assembly with missing dependencies
                    TestLog.LoadingAssemblyFailedWarning(ex.FileName, sourceAssembly);
                }
                catch (UnsupportedFrameworkException)
                {
                    TestLog.UnsupportedFrameworkWarning(sourceAssembly);
                }
                catch (Exception ex)
                {

                    TestLog.SendErrorMessage("Exception thrown discovering tests in " + sourceAssembly, ex);
                }
                finally
                {
                    runner.Unload();
                }
            }

            Info("discovering test", "finished");
        }
Esempio n. 26
0
        private Test MakeTest(TestDomain testDomain, string assemblyName)
		{
			NUnitProject project;
                
			project = NUnitProject.FromAssembly(assemblyName);
                                 
			return testDomain.Load(project);
        }
Esempio n. 27
0
		public int Execute( ConsoleOptions options )
		{
			XmlTextReader transformReader = GetTransformReader(options);
			if(transformReader == null) return 3;

			ConsoleWriter outStream = options.isOut
				? new ConsoleWriter( new StreamWriter( options.output ) )
				: new ConsoleWriter(Console.Out);

			ConsoleWriter errorStream = options.isErr
				? new ConsoleWriter( new StreamWriter( options.err ) )
				: new ConsoleWriter(Console.Error);

			TestDomain testDomain = new TestDomain(outStream, errorStream);
			if ( options.noshadow  ) testDomain.ShadowCopyFiles = false;

			Test test = MakeTestFromCommandLine(testDomain, options);

			if(test == null)
			{
				Console.Error.WriteLine("Unable to locate fixture {0}", options.fixture);
				return 2;
			}

			Directory.SetCurrentDirectory(new FileInfo((string)options.Parameters[0]).DirectoryName);
		
			EventCollector collector = new EventCollector( options, outStream );

			string savedDirectory = Environment.CurrentDirectory;

			if (options.HasInclude)
			{
				Console.WriteLine( "Included categories: " + options.include );
				testDomain.SetFilter( new CategoryFilter( options.IncludedCategories ) );
			}
			else if ( options.HasExclude )
			{
				Console.WriteLine( "Excluded categories: " + options.exclude );
				testDomain.SetFilter( new CategoryFilter( options.ExcludedCategories, true ) );
			}

			TestResult result = null;
			if ( options.thread )
			{
				testDomain.RunTest( collector );
				testDomain.Wait();
				result = testDomain.Result;
			}
			else
			{
				result = testDomain.Run( collector );
			}

			Directory.SetCurrentDirectory( savedDirectory );
			
			Console.WriteLine();
			Console.WriteLine();
			collector.PrintSummary( result );
			Console.WriteLine();

			string xmlOutput = CreateXmlOutput( result );
			
			if (options.xmlConsole)
				Console.WriteLine(xmlOutput);
			else
				CreateSummaryDocument(xmlOutput, transformReader, outStream);

			// Write xml output here
			string xmlResultFile = options.IsXml ? options.xml : "TestResult.xml";

			using ( StreamWriter writer = new StreamWriter( xmlResultFile ) ) 
			{
				writer.Write(xmlOutput);
			}
			outStream.Flush();
			errorStream.Flush();

			if ( testDomain != null )
				testDomain.Unload();

			return result.IsFailure ? 1 : 0;
		}
Esempio n. 28
0
		private static TestRunner MakeRunnerFromCommandLine( ConsoleOptions options )
		{
			TestPackage package;
			ConsoleOptions.DomainUsage domainUsage = ConsoleOptions.DomainUsage.Default;

			if (options.IsTestProject)
			{
				NUnitProject project = NUnitProject.LoadProject((string)options.Parameters[0]);
				string configName = options.config;
				if (configName != null)
					project.SetActiveConfig(configName);

				package = project.ActiveConfig.MakeTestPackage();
				package.TestName = options.fixture;

				domainUsage = ConsoleOptions.DomainUsage.Single;
			}
			else if (options.Parameters.Count == 1)
			{
				package = new TestPackage((string)options.Parameters[0]);
				domainUsage = ConsoleOptions.DomainUsage.Single;
			}
			else
			{
				package = new TestPackage("UNNAMED", options.Parameters);
				domainUsage = ConsoleOptions.DomainUsage.Multiple;
			}

			if (options.domain != ConsoleOptions.DomainUsage.Default)
				domainUsage = options.domain;
                    
			TestRunner testRunner = null;
				
			switch( domainUsage )
			{
				case ConsoleOptions.DomainUsage.None:
					testRunner = new NUnit.Core.RemoteTestRunner();
					// Make sure that addins are available
					CoreExtensions.Host.AddinRegistry = Services.AddinRegistry;
					break;

				case ConsoleOptions.DomainUsage.Single:
					testRunner = new TestDomain();
					break;

				case ConsoleOptions.DomainUsage.Multiple:
					testRunner = new MultipleTestDomainRunner();
					break;
			}

			package.TestName = options.fixture;
			package.Settings["ShadowCopyFiles"] = !options.noshadow;
			package.Settings["UseThreadedRunner"] = !options.nothread;
			testRunner.Load( package );

			return testRunner;
		}
Esempio n. 29
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;
        }