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