public void AppDomainUnloadedBug() { TestDomain domain = new TestDomain(); domain.Load( new TestPackage( mockDll ) ); domain.Run(new NullListener(), TestFilter.Empty, false, LoggingThreshold.Off); domain.Unload(); }
public void AppDomainUnloadedBug() { TestDomain domain = new TestDomain(); domain.Load( new TestPackage( "mock-assembly.dll" ) ); domain.Run(new NullListener()); domain.Unload(); }
public void AppDomainUnloadedBug() { TestDomain domain = new TestDomain(); domain.Load( new TestPackage( mockDll ) ); domain.Run(new NullListener()); domain.Unload(); }
public void UnloadRunner() { if (domain != null) { domain.Unload(); } }
public void AppDomainUnloadedBug() { TestDomain domain = new TestDomain(); domain.Load(new TestPackage("mock-assembly.dll")); domain.Run(new NullListener()); domain.Unload(); }
public void AppDomainUnloadedBug() { TestDomain domain = new TestDomain(); domain.Load(new TestPackage(mockDll)); domain.Run(new NullListener(), TestFilter.Empty, false, LoggingThreshold.Off); domain.Unload(); }
public void AppDomainUnloadedBug() { TestDomain domain = new TestDomain(); domain.Load(new TestPackage(mockDll)); domain.Run(new NullListener()); domain.Unload(); }
public void UnloadTestDomain() { if (testDomain != null) { testDomain.Unload(); } loadedTest = null; testDomain = null; }
public void UnloadTestDomain() { testDomain.Unload(); testDomain = null; FileInfo info = new FileInfo(tempFile); if (info.Exists) { info.Delete(); } }
public void LoadFixture() { TestDomain domain = new TestDomain(); TestPackage package = new TestPackage( "Multiple Assemblies Test" ); package.Assemblies.Add( Path.GetFullPath( "nonamespace-assembly.dll" ) ); package.Assemblies.Add( Path.GetFullPath( "mock-assembly.dll" ) ); package.TestName = "NUnit.Tests.Assemblies.MockTestFixture"; try { domain.Load(package); Assert.AreEqual(MockTestFixture.Tests, domain.Test.TestCount); } finally { domain.Unload(); } }
public void LoadFixture() { TestDomain domain = new TestDomain(); TestPackage package = new TestPackage("Multiple Assemblies Test"); package.Assemblies.Add(NoNamespaceTestFixture.AssemblyPath); package.Assemblies.Add(MockAssembly.AssemblyPath); package.TestName = "NUnit.Tests.Assemblies.MockTestFixture"; try { domain.Load(package); Assert.AreEqual(MockTestFixture.Tests, domain.Test.TestCount); } finally { domain.Unload(); } }
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(); } }
public void ResultStillValidAfterDomainUnload() { TestDomain domain = new TestDomain(Console.Out, Console.Error); Test test = domain.Load("mock-assembly.dll"); Assert.IsNotNull(test); TestResult result = domain.Run(new NullListener()); TestSuiteResult suite = result as TestSuiteResult; Assert.IsNotNull(suite); TestCaseResult caseResult = findCaseResult(suite); Assert.IsNotNull(caseResult); TestResultItem item = new TestResultItem(caseResult); domain.Unload(); string message = item.GetMessage(); Assert.IsNotNull(message); }
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(); } } } }
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.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(); } } Info("discovering test", "finished"); }
public void UnloadTestDomain() { domain.Unload(); domain = null; }
public void LoadFixture() { TestDomain domain = new TestDomain(); TestPackage package = new TestPackage( "Multiple Assemblies Test" ); package.Assemblies.Add(NoNamespaceTestFixture.AssemblyPath); package.Assemblies.Add(MockAssembly.AssemblyPath); package.TestName = "NUnit.Tests.Assemblies.MockTestFixture"; try { domain.Load(package); Assert.AreEqual(MockTestFixture.Tests, domain.Test.TestCount); } finally { domain.Unload(); } }
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(); } } } }
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 LoadFixture() { TestDomain domain = new TestDomain(); TestPackage package = new TestPackage( "Multiple Assemblies Test" ); package.Assemblies.Add( Path.GetFullPath( "nonamespace-assembly.dll" ) ); package.Assemblies.Add( Path.GetFullPath( "mock-assembly.dll" ) ); package.TestName = "NUnit.Tests.Assemblies.MockTestFixture"; try { domain.Load(package); Assert.AreEqual(MockTestFixture.Tests, domain.Test.TestCount); } finally { domain.Unload(); } }
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); EventListener 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(); string xmlOutput = CreateXmlOutput(result); if (options.xmlConsole) { Console.WriteLine(xmlOutput); } else { CreateSummaryDocument(xmlOutput, transformReader); } // Write xml output here string xmlResultFile = options.IsXml ? options.xml : "TestResult.xml"; using (StreamWriter writer = new StreamWriter(xmlResultFile)) { writer.Write(xmlOutput); } if (testDomain != null) { testDomain.Unload(); } return(result.IsFailure ? 1 : 0); }
public void TearDown() { testDomain.Unload(); }
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"); } } } }