internal static PNUnitTestResult BuildError( PNUnitTestInfo pnunitTestInfo, Exception e, TestConsoleAccess consoleAccess, TestLogInfo testLogInfo) { TestName testName = new TestName(); testName.Name = pnunitTestInfo.TestName; testName.FullName = pnunitTestInfo.TestName; testName.TestID = new TestID(); PNUnitTestResult result = new PNUnitTestResult( testName, pnunitTestInfo.GetTestOutput(), testLogInfo.OSVersion, testLogInfo.BackendType); string fullMessage = string.Format( "{0}; EXCEPTION TYPE: {1}; STACK TRACE: {2}", e.Message, e.GetType(), e.StackTrace); result.Failure(fullMessage, string.Empty); pnunitTestInfo.DeleteTestOutput(); return(result); }
static void InitPNUnitServices( PNUnitTestInfo testInfo, TestRunner testRunner, IPNUnitServices services, TestConsoleAccess consoleAccess, TestLogInfo testLogInfo) { // Intialize the singleton new PNUnitServices(testInfo, services, consoleAccess, testLogInfo); }
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); } }
internal static PNUnitTestResult BuildResult( PNUnitTestInfo pnunittestinfo, TestResult result, TestConsoleAccess consoleAccess, TestLogInfo testLogInfo) { string output = pnunittestinfo.GetTestOutput(); pnunittestinfo.DeleteTestOutput(); mLog.Debug("Going to build the result ..."); if (result == null) { mLog.Debug("Going to build an error result ..."); TestName testName = new TestName(); testName.Name = pnunittestinfo.TestName; testName.FullName = pnunittestinfo.TestName; testName.TestID = new TestID(); string errorMsg = string.Format( "The test {0} couldn't be found in the assembly {1}", pnunittestinfo.TestToRun, pnunittestinfo.AssemblyName); PNUnitTestResult testResult = new PNUnitTestResult( testName, output, testLogInfo.OSVersion, testLogInfo.BackendType); testResult.Failure(errorMsg, string.Empty); return(testResult); } PNUnitTestResult myResult = new PNUnitTestResult(result, output, testLogInfo.OSVersion, testLogInfo.BackendType); return(myResult); }
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); } }
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); }
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); }