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"); } } } }
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 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; }
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; }