TestRunner SetupTest(IPNUnitServices services, TestConsoleAccess consoleAccess, TestLogInfo testLogInfo) { Directory.SetCurrentDirectory(Path.GetDirectoryName(mNUnitAssemblyPath)); TestPackage package = new TestPackage(Path.GetFileName(mNUnitAssemblyPath)); TestRunner result = new SimpleTestRunner(); AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); bool testLoaded = result.Load(package); if (!testLoaded) { mLog.InfoFormat("Unable to locate test {0}", mPNUnitTestInfo.TestName); PNUnitTestResult testResult = PNUnitTestRunner.BuildError( mPNUnitTestInfo, new Exception("Unable to locate tests"), consoleAccess, testLogInfo); services.NotifyResult( mPNUnitTestInfo.TestName, testResult); return(null); } InitPNUnitServices( mPNUnitTestInfo, result, services, consoleAccess, testLogInfo); return(result); }
static void RunPreload(string pathToAssemblies) { mLog.Debug("Preload started. Path To assemblies:" + pathToAssemblies); InitServices.InitNUnitServices(); PNUnitTestRunner runner = new PNUnitTestRunner(pathToAssemblies); runner.Preload(); int pidOfThisExpectedByAgent = Codice.Test.PlatformIdentifier.IsWindows() ? System.Diagnostics.Process.GetCurrentProcess().Id : Mono.Unix.UnixEnvironment.GetParentProcessId(); string testInfoFile = Path.Combine( Path.GetTempPath(), PNUnit.Agent.AssemblyPreload.PRELOADED_PROCESS_FILE_PREFIX + pidOfThisExpectedByAgent.ToString()); int count = 0; while (!File.Exists(testInfoFile)) { System.Threading.Thread.Sleep(150); mLog.DebugFormat("Waiting for testinfo file to be created...: {0}", testInfoFile); count++; if (count >= 6000) //wait 1,5 minutes for test arrival { mLog.Fatal("Tired of waiting: Cannot execute tests without information; exiting ..."); Environment.Exit(1); } } mLog.DebugFormat("Preload read {0} from file", testInfoFile); PNUnitTestInfo info = TestInfoReader.ReadTestInfo(testInfoFile); if (info == null) { mLog.Fatal("Cannot execute tests without information; exiting ..."); Environment.Exit(1); } ProcessNameSetter.SetProcessName(info.TestName); IPNUnitServices services = PNUnitServices.GetPNunitServicesProxy(info.PNUnitServicesServer); runner.Run(info, services, null); }
public void Run(IPNUnitServices services) { try { TestResult result = null; TestRunner testRunner = null; TestConsoleAccess consoleAccess = new TestConsoleAccess(mPNUnitTestInfo.OutputFile); TestLogInfo testLogInfo = new TestLogInfo(); try { mLog.DebugFormat("Running test assembly {0}", mNUnitAssemblyPath); ConsoleWriter outStream = new ConsoleWriter(Console.Out); ConsoleWriter errorStream = new ConsoleWriter(Console.Error); testRunner = SetupTest(services, consoleAccess, testLogInfo); if (testRunner == null) { return; } mLog.Debug("Running tests"); try { PNUnitServices.Get().InitBarriers(); PNUnitServices.Get().EnterBarrier(PNUnitServices.Get().GetTestStartBarrier()); result = RunNUnitAssembly( services, outStream, testRunner, Path.GetFileNameWithoutExtension(mPNUnitTestInfo.AssemblyName)); PNUnitServices.Get().EnterBarrier(PNUnitServices.Get().GetTestEndBarrier()); } catch (Exception e) { mLog.ErrorFormat("Error running test {0}. {1}", mPNUnitTestInfo.TestName, e.Message); mLog.Debug(e.StackTrace); result = PNUnitTestRunner.BuildError( mPNUnitTestInfo, e, consoleAccess, testLogInfo); } } finally { mLog.Info("Notifying the results"); PNUnitTestResult pnunitResult = PNUnitTestRunner.BuildResult( mPNUnitTestInfo, result, consoleAccess, testLogInfo); mLog.Debug("Result built!! Now, notify the launcher ..."); try { services.NotifyResult( mPNUnitTestInfo.TestName, pnunitResult); mLog.Debug("<-Results NOTIFIED"); } catch (Exception e) { mLog.ErrorFormat( "Error notifying back the result of test {0}. {1}", mPNUnitTestInfo.TestName, e.Message); mLog.Error( "If you're using a custom launcher.remoting.conf" + " check that you've defined the binaryFormatter"); } result = null; UnloadTests(testRunner); } } catch (Exception ex) { mLog.ErrorFormat("Error running test {0} {1}", mPNUnitTestInfo.TestName, ex.Message); mLog.Debug(ex.StackTrace); } }