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); }
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 NotifyResult(string TestName, PNUnitTestResult result) { log.DebugFormat("NotifyResult called for TestGroup {0}, Test {1}", mTestGroup.Name, TestName); lock (mResultLock) { log.DebugFormat("NotifyResult lock entered for TestGroup {0}, Test {1}", mTestGroup.Name, TestName); mResults.Add(result); if (mResults.Count == mLaunchedTests) { log.DebugFormat("All the tests notified the results, waking up. mResults.Count == {0}", mResults.Count); mFinish.Set(); } } lock ( mBarriers ) { if (mBarriersOfTests.Contains(TestName)) { log.DebugFormat("Going to abandon barriers of test {0}", TestName); IList list = (IList)mBarriersOfTests[TestName]; foreach (string barrier in list) { log.DebugFormat("Abandoning barrier {0}", barrier); ((Barrier)mBarriers[barrier]).Abandon(); } } } log.DebugFormat("NotifyResult finishing for TestGroup {0}, Test {1}.", mTestGroup.Name, TestName); log.InfoFormat("Result for TestGroup {0}, Test {1}: {2}", mTestGroup.Name, TestName, result.IsSuccess ? "PASS" : "FAIL"); }
private TestResult BuildResult( TestResult result, TestConsoleAccess consoleAccess, PNUnitTestInfo testInfo) { //the test namespace contains errors if (result == null) { TestName testName = new TestName(); testName.Name = testInfo.TestName; string errormsg = "The test {0} couldn't be found in the assembly {1}"; result = new PNUnitTestResult(testName, string.Empty); result.Failure( string.Format(errormsg, testInfo.TestToRun, testInfo.AssemblyName), string.Empty); return(result); } if (!result.IsSuccess /*|| ReturnTestOutput()*/) { return(new PNUnitTestResult(result, consoleAccess.GetTestOutput())); } else { return(result); } }
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); }
internal void AddTestResult(PNUnitTestResult testResult) { lock (mResultLock) { mResults.Add(testResult); } }
private TestResult BuildError(string message, TestConsoleAccess consoleAccess) { TestName testName = new TestName(); testName.Name = mPNUnitTestInfo.TestName; testName.FullName = mPNUnitTestInfo.TestName; testName.TestID = new TestID(); TestResult result = new PNUnitTestResult(testName, consoleAccess.GetTestOutput()); result.Failure(message, string.Empty); return(result); }
private TestResult BuildError(Exception e, TestConsoleAccess consoleAccess) { TestName testName = new TestName(); testName.Name = mPNUnitTestInfo.TestName; testName.FullName = mPNUnitTestInfo.TestName; testName.TestID = new TestID(); TestResult result = new PNUnitTestResult(testName, consoleAccess.GetTestOutput()); result.Error(e); return(result); }
public PNUnitTestResult[] GetTestResults() { lock (mResultLock) { PNUnitTestResult[] result = new PNUnitTestResult[mResults.Count]; int i = 0; foreach (PNUnitTestResult res in mResults) { result[i++] = res; } return(result); } }
private static void PrintResult(int testNumber, PNUnitTestResult res) { Console.WriteLine( "({0})Name: {1}\n Result: {2,-12} Assert Count: {3,-2} Time: {4,5}", testNumber, res.Name, res.IsSuccess ? "SUCCESS" : (res.IsFailure ? "FAILURE" : (!res.Executed ? "NOT EXECUTED": "UNKNOWN")), res.AssertCount, res.Time); if (!res.IsSuccess) { Console.WriteLine("\nMessage: {0}\nStack Trace:\n{1}\n\n", res.Message, res.StackTrace); } }
static string CollectOutput(PNUnitTestResult tr) { StringBuilder sb = new StringBuilder(); sb.Append(tr.Output); if (tr.Results != null && tr.Results.Count > 0) { foreach (TestResult child in tr.Results) { DoCollectOutput(child, sb); } } return(sb.ToString()); }
void NotifyException( PNUnitService service, TestConf test, Exception e) { TestName tn = new TestName(); tn.Name = test.Name; string fullMessage = string.Format( "{0}; EXCEPTION TYPE: {1}; STACK TRACE: {2}", e.Message, e.GetType(), e.StackTrace); PNUnitTestResult tr = new PNUnitTestResult(tn, fullMessage, string.Empty, string.Empty); tr.Failure(fullMessage, e.StackTrace); service.NotifyResult(test.Name, tr); }
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); }
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"); } } } }
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); } }
void IPNUnitServices.NotifyResult(string testName, PNUnitTestResult result) { }
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 NotifyResult(string testName, PNUnitTestResult result) { mLog.DebugFormat("NotifyResult called for TestGroup {0}, Test {1}", mTestGroup.Name, testName); int count = 0; mLog.DebugFormat( "NotifyResult lock entered for TestGroup {0}, Test {1}", mTestGroup.Name, testName); mTestsRun.AddExecutedTest(testName); mTestsRun.AddTestResult(result); count = mTestsRun.TestsResultsCount; lock (mBarriers) { if (mBarriersOfTests.ContainsKey(testName)) { mLog.DebugFormat("Going to abandon barriers of test {0}", testName); IList list = (IList)mBarriersOfTests[testName]; foreach (string barrier in list) { mLog.DebugFormat("Abandoning barrier {0}", barrier); mBarriers[barrier].Abandon(); } } } mLog.DebugFormat( "NotifyResult finishing for TestGroup {0}, Test {1}.", mTestGroup.Name, testName); string machine = Runner.GetTestConfFromName(mTestGroup, testName).Machine; string resultText = result.IsSuccess ? "PASS" : "FAIL"; if (!result.Executed) { resultText = "IGNORED"; } string message = string.Format( "Result for TestGroup {0}, Test {1}: {2}. Time {3} ms. {4}/{5} tests finished. Agent: {6}", mTestGroup.Name, testName, resultText, Environment.TickCount - mInitialTime, count, mTestsRun.LaunchedCount, machine); string logTestName = string.Format("{0}.{1}", mTestGroup.Name, testName); if (!result.Executed) { mLogWriter.LogWarn(message); mLogWriter.WriteTestLog(logTestName, result, machine); return; } if (result.IsSuccess) { mLogWriter.Log(message); mLogWriter.WriteTestLog(logTestName, result, machine); } else { mLogWriter.LogError(message); mLogWriter.WriteFailedTestLog(logTestName, result, machine); } if (mTestsRun.AllTestsFinished()) { mLog.DebugFormat( "All the tests notified the results, waking up. mResults.Count == {0}", mTestsRun.TestsResultsCount); mFinish.Set(); } }
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); } }