TestResult RunNUnitAssembly( IPNUnitServices services, ConsoleWriter outStream, TestRunner testRunner, string assemblyName) { ITestFilter testFilter = TestFilter.Empty; string excludeFilterString = GetExcludeFilter(); if (!string.IsNullOrEmpty(excludeFilterString)) { testFilter = new NotFilter( new CategoryExpression(excludeFilterString).Filter); } int testCount = testRunner.CountTestCases(testFilter); EventCollector collector = new EventCollector(outStream, testCount, services, assemblyName); TestResult result = testRunner.Run( collector, testFilter, true, LoggingThreshold.All); collector.NotifyProgress(); return(result); }
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); }
internal static void NotifyError(Exception e, PNUnitTestInfo info) { TestLogInfo testLogInfo = new TestLogInfo(); testLogInfo.SetOSVersion(Environment.OSVersion.Platform.ToString()); TestName testName = new TestName(); testName.Name = info.TestName; testName.FullName = info.TestName; testName.TestID = new TestID(); PNUnitTestResult result = new PNUnitTestResult( testName, info.GetTestOutput(), testLogInfo.OSVersion, testLogInfo.BackendType, true); string fullMessage = string.Format( "TestName: {0}; Error: {1}; EXCEPTION TYPE: {2}; STACK TRACE: {3}", testName.Name, e.Message, e.GetType(), e.StackTrace); result.Failure(fullMessage, string.Empty); info.DeleteTestOutput(); IPNUnitServices services = PNUnitServices.GetPNunitServicesProxy(info.PNUnitServicesServer); services.NotifyResult(info.TestName, result); }
public TestInfo(string TestName, string AssemblyName, string TestToRun, string[] TestParams, IPNUnitServices Services) { this.TestName = TestName; this.AssemblyName = AssemblyName; this.TestToRun = TestToRun; this.TestParams = TestParams; this.Services = Services; }
public static IPNUnitServices GetPNunitServicesProxy(string server) { // this server is the launcher host:port IPNUnitServices result = (IPNUnitServices)Activator.GetObject( typeof(IPNUnitServices), string.Format("tcp://{0}/{1}", server, PNUNIT_SERVICES_NAME)); return(result); }
static void InitPNUnitServices( PNUnitTestInfo testInfo, TestRunner testRunner, IPNUnitServices services, TestConsoleAccess consoleAccess, TestLogInfo testLogInfo) { // Intialize the singleton new PNUnitServices(testInfo, services, consoleAccess, testLogInfo); }
public EventCollector( ConsoleWriter writer, int testCount, IPNUnitServices services, string assemblyName) { mWriter = writer; mCurrentTestName = string.Empty; mTotalTestCount = testCount; mServices = services; mAssemblyName = assemblyName; }
public PNUnitTestInfo(string TestName, string AssemblyName, string TestToRun, string[] TestParams, IPNUnitServices Services, string StartBarrier, string EndBarrier, string[] WaitBarriers) { this.TestName = TestName; this.AssemblyName = AssemblyName; this.TestToRun = TestToRun; this.TestParams = TestParams; this.Services = Services; this.StartBarrier = StartBarrier; this.EndBarrier = EndBarrier; this.WaitBarriers = WaitBarriers; }
// To be used only by the runner public PNUnitServices( PNUnitTestInfo info, IPNUnitServices services, ITestConsoleAccess consoleAccess, ITestLogInfo testLogInfo) { mInfo = info; mServices = services; mConsoles = new ArrayList(); mConsoles.Add(consoleAccess); mTestLogInfo = testLogInfo; mInstance = this; }
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 PNUnitTestInfo( string TestName, string AssemblyName, string TestToRun, string[] TestParams, IPNUnitServices Services, string StartBarrier, string EndBarrier, string[] WaitBarriers) { this.TestName = TestName; this.AssemblyName = AssemblyName; this.TestToRun = TestToRun; this.TestParams = TestParams; this.Services = Services; this.StartBarrier = StartBarrier; this.EndBarrier = EndBarrier; this.WaitBarriers = WaitBarriers; }
static void CreatePNUnitServices( PNUnitTestInfo testInfo, TestRunner testRunner, IPNUnitServices services, TestConsoleAccess consoleAccess, TestLogInfo testLogInfo, ITestConsoleAccess extraConsoleAccess) { // Intialize the singleton new PNUnitServices(testInfo, services, consoleAccess, testLogInfo); if (extraConsoleAccess != null) { PNUnitServices.Get().RegisterConsole(extraConsoleAccess); } }
public void Run(object state) { InitServices.InitNUnitServices(); PNUnitTestInfo testInfo = TestInfoReader.ReadTestInfo(mTestInfoFile); if (testInfo == null) { Console.Error.WriteLine("Cannot execute tests without information. Exiting..."); mGuiFinalizer.Finalize(1); } IPNUnitServices services = GetPNUnitServices(testInfo.PNUnitServicesServer); PNUnitTestRunner.PNUnitTestRunner runner = new PNUnitTestRunner.PNUnitTestRunner(mPathToAssemblies); runner.Run(testInfo, services, mGuiConsole); GuiTestAssemblyResolver.UninstallAssemblyResolver(); mGuiFinalizer.Finalize(1); }
static void RunOnce(string testInfoFile, string pathToAssemblies) { PNUnitTestInfo info = TestInfoReader.ReadTestInfo(testInfoFile); if (info == null) { Console.WriteLine("Cannot execute tests without information; exiting ..."); Environment.Exit(1); } ProcessNameSetter.SetProcessName(info.TestName); IPNUnitServices services = PNUnitServices.GetPNunitServicesProxy(info.PNUnitServicesServer); if (info.TestName.StartsWith("run-nunit")) { new NUnitTestRunner(info, pathToAssemblies).Run(services); return; } new PNUnitTestRunner(pathToAssemblies).Run(info, services, null); }
TestRunner SetupTest( PNUnitTestInfo testInfo, IPNUnitServices services, TestConsoleAccess consoleAccess, TestLogInfo testLogInfo, ITestConsoleAccess extraConsoleAccess) { TestRunner result; bool testAssemblyLoaded; if (mPreloader == null) { result = new SimpleTestRunner(); int ini = Environment.TickCount; string fullAssemblyPath = Path.GetFullPath( Path.Combine(mPathToAssemblies, testInfo.AssemblyName)); mLog.DebugFormat("Loading test assembly from {0}", fullAssemblyPath); testAssemblyLoaded = MakeTest(result, fullAssemblyPath); mLog.DebugFormat("Load test assembly {0} ms", Environment.TickCount - ini); } else { //if (!AssemblyPreload.CanUsePreload(testInfo.AssemblyName)) //{ // throw new Exception( // "The preloaded and the target assembly don't match!!"); //} result = mPreloader.TestRunner; testAssemblyLoaded = mPreloader.TestAssemblyLoaded; } if (!testAssemblyLoaded) { mLog.InfoFormat("Unable to load test assembly {0} for test {1}", testInfo.AssemblyName, testInfo.TestName); PNUnitTestResult testResult = BuildError( testInfo, new Exception("Unable to locate tests"), consoleAccess, testLogInfo); services.NotifyResult( testInfo.TestName, testResult); return(null); } mLog.Debug("Test loaded, going to set CurrentDirectory"); Directory.SetCurrentDirectory(mPathToAssemblies); mLog.Debug("Creating PNUnit services"); CreatePNUnitServices(testInfo, result, services, consoleAccess, testLogInfo, extraConsoleAccess); return(result); }
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); } }
public void Run( PNUnitTestInfo testInfo, IPNUnitServices services, ITestConsoleAccess extraConsoleAccess) { try { TestResult result = null; TestRunner testRunner = null; TestConsoleAccess consoleAccess = new TestConsoleAccess(testInfo.OutputFile); TestLogInfo testLogInfo = new TestLogInfo(); try { mLog.DebugFormat("Running test {0}:{1} Assembly {2}", testInfo.TestName, testInfo.TestToRun, testInfo.AssemblyName); ConsoleWriter outStream = new ConsoleWriter(Console.Out); ConsoleWriter errorStream = new ConsoleWriter(Console.Error); testRunner = SetupTest(testInfo, services, consoleAccess, testLogInfo, extraConsoleAccess); if (testRunner == null) { return; } mLog.DebugFormat("RunTest {0}", testInfo.TestName); PrintSeparator(); try { result = RunTest(testInfo, outStream, testRunner); } catch (Exception e) { mLog.ErrorFormat("Error running test {0}. {1}", testInfo.TestName, e.Message); mLog.Debug(e.StackTrace); result = BuildError(testInfo, e, consoleAccess, testLogInfo); } } catch (Exception e) { mLog.ErrorFormat("Error launching tests: {0}", e.Message); mLog.Debug(e.StackTrace); result = BuildError(testInfo, e, consoleAccess, testLogInfo); } finally { mLog.InfoFormat("Notifying the results {0}", testInfo.TestName); PNUnitTestResult pnunitResult = BuildResult( testInfo, result, consoleAccess, testLogInfo); mLog.DebugFormat("Result built!! Now, notify the launcher ... {0}", testInfo.TestName); try { services.NotifyResult( testInfo.TestName, pnunitResult); mLog.DebugFormat("<-Results NOTIFIED - {0}", testInfo.TestName); } catch (Exception e) { mLog.ErrorFormat( "Error notifying back the result of test {0}. {1}", testInfo.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}", testInfo.TestName, ex.Message); mLog.Debug(ex.StackTrace); } }