public TcpTestListener (IRemoteEventListener listener) { TcpListener = new TcpListener (new IPEndPoint (IPAddress.Loopback, 0)); TcpListener.Start (); Task.Factory.StartNew (() => { try { using (var client = TcpListener.AcceptTcpClient ()) using (var socketStream = client.GetStream ()) using (var reader = new StreamReader (socketStream, Encoding.UTF8)) { string line = null; while ((line = reader.ReadLine ()) != null) { var element = XElement.Parse (line); Gtk.Application.Invoke (delegate { var testName = element.Attribute ("name").Value; if (element.Name.LocalName == "suite-started") { listener.SuiteStarted (testName); } else if (element.Name.LocalName == "test-started") { listener.TestStarted (testName); } else if (element.Name.LocalName == "test-finished") { listener.TestFinished (testName, CreateResult (element)); } else if (element.Name.LocalName == "suite-finished") { listener.SuiteFinished (testName, CreateResult (element)); } }); } } } catch { } finally { TcpListener.Stop (); } }); }
/// <summary> /// Execute test cases. /// </summary> /// <param name="assembly">Assembly.</param> /// <param name="testInfos">Test infos.</param> /// <param name="executionListener">Execution listener.</param> /// <remarks>It uses xunit execution engine to execute the test cases.</remarks> public void Execute(string assembly, string[] nameFilter, IRemoteEventListener executionListener) { var lookup = new HashSet <string>(); foreach (var testId in nameFilter) { lookup.Add(testId); } TestAssemblyConfiguration conf = LoadTestAssemblyConfiguration(assembly); var discoveryOptions = TestFrameworkOptions.ForDiscovery(conf); var executionOptions = TestFrameworkOptions.ForExecution(conf); executionOptions.SetSynchronousMessageReporting(true); // we don't want to run every test in the assembly // only the tests passed in "testInfos" argument using (var controller = new XunitFrontController(conf.AppDomainOrDefault, assembly, null, conf.ShadowCopyOrDefault, null, new NullSourceInformationProvider())) using (var discoveryVisitor = new DefaultDiscoveryVisitor(tc => lookup.Contains(tc.UniqueID))) using (var executionVisitor = new DefaultExecutionVisitor(executionListener)) { controller.Find(false, discoveryVisitor, discoveryOptions); discoveryVisitor.Finished.WaitOne(); controller.RunTests(discoveryVisitor.TestCases, executionVisitor, executionOptions); executionVisitor.Finished.WaitOne(); } }
public UnitTestResult Run (IRemoteEventListener listener, ITestFilter filter, string path, string suiteName, List<string> supportAssemblies) { NUnitTestRunner runner = GetRunner (path); EventListenerWrapper listenerWrapper = listener != null ? new EventListenerWrapper (listener) : null; TestResult res = runner.Run (listenerWrapper, filter, path, suiteName, supportAssemblies); return listenerWrapper.GetLocalTestResult (res); }
public UnitTestResult Run(IRemoteEventListener listener, ITestFilter filter, string path, string suiteName, List <string> supportAssemblies) { NUnitTestRunner runner = GetRunner(path); EventListenerWrapper listenerWrapper = listener != null ? new EventListenerWrapper(listener) : null; TestResult res = runner.Run(listenerWrapper, filter, path, suiteName, supportAssemblies); return(listenerWrapper.GetLocalTestResult(res)); }
public UnitTestResult Run(IRemoteEventListener listener, ITestFilter filter, string path, string suiteName, List <string> supportAssemblies, string testRunnerType, string testRunnerAssembly, string crashLogFile) { NUnitTestRunner runner = GetRunner(path); EventListenerWrapper listenerWrapper = listener != null ? new EventListenerWrapper(listener) : null; UnhandledExceptionEventHandler exceptionHandler = (object sender, UnhandledExceptionEventArgs e) => { var ex = new RemoteUnhandledException((Exception)e.ExceptionObject); File.WriteAllText(crashLogFile, ex.Serialize()); }; AppDomain.CurrentDomain.UnhandledException += exceptionHandler; try { TestResult res = runner.Run(listenerWrapper, filter, path, suiteName, supportAssemblies, testRunnerType, testRunnerAssembly); return(listenerWrapper.GetLocalTestResult(res)); } finally { AppDomain.CurrentDomain.UnhandledException -= exceptionHandler; } }
public UnitTestResult Run (IRemoteEventListener listener, ITestFilter filter, string path, string suiteName, List<string> supportAssemblies, string testRunnerType, string testRunnerAssembly, string crashLogFile) { NUnitTestRunner runner = GetRunner (path); EventListenerWrapper listenerWrapper = listener != null ? new EventListenerWrapper (listener) : null; UnhandledExceptionEventHandler exceptionHandler = (object sender, UnhandledExceptionEventArgs e) => { var ex = new RemoteUnhandledException ((Exception) e.ExceptionObject); File.WriteAllText (crashLogFile, ex.Serialize ()); }; AppDomain.CurrentDomain.UnhandledException += exceptionHandler; try { TestResult res = runner.Run (listenerWrapper, filter, path, suiteName, supportAssemblies, testRunnerType, testRunnerAssembly); return listenerWrapper.GetLocalTestResult (res); } finally { AppDomain.CurrentDomain.UnhandledException -= exceptionHandler; } }
public async Task <UnitTestResult> Run(IRemoteEventListener listener, string[] nameFilter, string path, string suiteName, List <string> supportAssemblies, string testRunnerType, string testRunnerAssembly, string crashLogFile) { this.listener = listener; var msg = new RunRequest { NameFilter = nameFilter, Path = path, SuiteName = suiteName, SupportAssemblies = supportAssemblies.ToArray(), TestRunnerType = testRunnerType, TestRunnerAssembly = testRunnerAssembly, CrashLogFile = crashLogFile }; var r = (await connection.SendMessage(msg)).Result; await connection.ProcessPendingMessages(); return(ToUnitTestResult(r)); }
public async Task<UnitTestResult> Run (IRemoteEventListener listener, string[] nameFilter, string path, string suiteName, List<string> supportAssemblies, string testRunnerType, string testRunnerAssembly, string crashLogFile) { this.listener = listener; var msg = new RunRequest { NameFilter = nameFilter, Path = path, SuiteName = suiteName, SupportAssemblies = supportAssemblies.ToArray (), TestRunnerType = testRunnerType, TestRunnerAssembly = testRunnerAssembly, CrashLogFile = crashLogFile }; var r = (await connection.SendMessage (msg)).Result; await connection.ProcessPendingMessages (); return ToUnitTestResult (r); }
public TcpTestListener(IRemoteEventListener listener) { TcpListener = new TcpListener(new IPEndPoint(IPAddress.Loopback, 0)); TcpListener.Start(); Task.Factory.StartNew(() => { try { using (var client = TcpListener.AcceptTcpClient()) using (var socketStream = client.GetStream()) using (var reader = new StreamReader(socketStream, Encoding.UTF8)) { string line = null; while ((line = reader.ReadLine()) != null) { var element = XElement.Parse(line); Gtk.Application.Invoke(delegate { var testName = element.Attribute("name").Value; if (element.Name.LocalName == "suite-started") { listener.SuiteStarted(testName); } else if (element.Name.LocalName == "test-started") { listener.TestStarted(testName); } else if (element.Name.LocalName == "test-finished") { listener.TestFinished(testName, CreateResult(element)); } else if (element.Name.LocalName == "suite-finished") { listener.SuiteFinished(testName, CreateResult(element)); } }); } } } catch { } finally { TcpListener.Stop(); } }); }
public TcpTestListener (IRemoteEventListener listener, string suiteName) { this.testSuiteName = suiteName; this.listener = listener; bool rootSuiteStarted = false; TcpListener = new TcpListener (new IPEndPoint (IPAddress.Loopback, 0)); TcpListener.Start (); Task.Factory.StartNew (() => { try { using (var client = TcpListener.AcceptTcpClient ()) using (var socketStream = client.GetStream ()) using (var reader = new StreamReader (socketStream, Encoding.UTF8)) { string line = null; while ((line = reader.ReadLine ()) != null) { var element = XElement.Parse (line); string testName = element.Attribute ("name").Value; var action = element.Name.LocalName; if (testSuiteName.Length == 0 && !rootSuiteStarted) { // Running the whole assembly rootTestName = testName; rootSuiteStarted = true; continue; } if (testSuiteName == testName && !rootSuiteStarted) { // Running a test suite rootTestName = testName; rootSuiteStarted = true; listener.SuiteStarted ("<root>"); continue; } if (!rootSuiteStarted) continue; switch (action) { case "suite-started": UpdateTestSuiteStatus (testName, false); break; case "test-started": UpdateTestSuiteStatus (testName, true); listener.TestStarted (testName); break; case "test-finished": var res = CreateResult (element); AddTestResult (res); listener.TestFinished (testName, res); break; case "suite-finished": if (testName == rootTestName) { FinishSuites (0); listener.SuiteFinished ("<root>", CreateResult (element)); rootSuiteStarted = false; } break; } } } } catch (Exception ex) { LoggingService.LogError ("Exception in test listener", ex); } finally { TcpListener.Stop (); } }); }
UnitTestResult ReportXmlResult (IRemoteEventListener listener, XElement elem, string testPrefix, bool macunitStyle) { UnitTestResult result = new UnitTestResult (); var time = (string)elem.Attribute ("time"); if (time != null) result.Time = TimeSpan.FromSeconds (double.Parse (time, CultureInfo.InvariantCulture)); result.TestDate = DateTime.Now; var reason = elem.Element ("reason"); if (reason != null) result.Message = (string) reason; var failure = elem.Element ("failure"); if (failure != null) { var msg = failure.Element ("message"); if (msg != null) result.Message = (string)msg; var stack = failure.Element ("stack-trace"); if (stack != null) result.StackTrace = (string)stack; } switch ((string)elem.Attribute ("result")) { case "Error": case "Failure": result.Status = ResultStatus.Failure; break; case "Success": result.Status = ResultStatus.Success; break; case "Ignored": result.Status = ResultStatus.Ignored; break; default: result.Status = ResultStatus.Inconclusive; break; } if (elem.Name == "test-suite") { // nunitlite does not emit <test-suite type="Namespace" elements so we need to fake // them by deconstructing the full type name and emitting the suite started events manually var names = new List<string> (); if (!macunitStyle || (string)elem.Attribute ("type") == "Assembly") names.Add ("<root>"); else names.AddRange (elem.Attribute ("name").Value.Split ('.')); for (int i = 0; i < names.Count; i ++) listener.SuiteStarted (testPrefix + string.Join (".", names.Take (i + 1))); var name = (string)elem.Attribute ("type") == "Assembly" ? "<root>" : (string) elem.Attribute ("name"); var cts = elem.Element ("results"); if (cts != null) { foreach (var ct in cts.Elements ()) { var r = ReportXmlResult (listener, ct, name != "<root>" ? testPrefix + name + "." : "", macunitStyle); result.Add (r); } } for (int i = 0; i < names.Count; i ++) listener.SuiteFinished (testPrefix + string.Join (".", names.Take (i + 1)), result); } else { string name = (string)elem.Attribute ("name"); switch (result.Status) { case ResultStatus.Success: result.Passed++; break; case ResultStatus.Failure: result.Failures++; break; case ResultStatus.Ignored: result.Ignored++; break; case ResultStatus.Inconclusive: result.Inconclusive++; break; } listener.TestStarted (name); listener.TestFinished (name, result); } return result; }
public TcpTestListener(IRemoteEventListener listener, string suiteName) { this.testSuiteName = suiteName; this.listener = listener; bool rootSuiteStarted = false; TcpListener = new TcpListener(new IPEndPoint(IPAddress.Loopback, 0)); TcpListener.Start(); Task.Run(() => { try { using (var client = TcpListener.AcceptTcpClient()) using (var socketStream = client.GetStream()) using (var reader = new StreamReader(socketStream, Encoding.UTF8)) { HasReceivedConnection = true; string line = null; while ((line = reader.ReadLine()) != null) { var element = XElement.Parse(line); string testName = element.Attribute("name").Value; var action = element.Name.LocalName; if (testSuiteName.Length == 0 && !rootSuiteStarted) { // Running the whole assembly rootTestName = testName; rootSuiteStarted = true; continue; } if (testSuiteName == testName && !rootSuiteStarted) { // Running a test suite rootTestName = testName; rootSuiteStarted = true; listener.SuiteStarted("<root>"); continue; } if (!rootSuiteStarted) { continue; } switch (action) { case "suite-started": UpdateTestSuiteStatus(testName, false); break; case "test-started": UpdateTestSuiteStatus(testName, true); listener.TestStarted(testName); break; case "test-finished": var res = CreateResult(element); AddTestResult(res); listener.TestFinished(testName, res); break; case "suite-finished": if (testName == rootTestName) { FinishSuites(0); listener.SuiteFinished("<root>", CreateResult(element)); rootSuiteStarted = false; } break; } } } } catch (Exception ex) { LoggingService.LogError("Exception in test listener", ex); } finally { TcpListener.Stop(); } }); }
public EventListenerWrapper(IRemoteEventListener wrapped) { this.wrapped = wrapped; }
UnitTestResult ReportXmlResult(IRemoteEventListener listener, XElement elem, string testPrefix, bool macunitStyle) { UnitTestResult result = new UnitTestResult(); var time = (string)elem.Attribute("time"); if (time != null) { result.Time = TimeSpan.FromSeconds(double.Parse(time, CultureInfo.InvariantCulture)); } result.TestDate = DateTime.Now; var reason = elem.Element("reason"); if (reason != null) { result.Message = (string)reason; } var failure = elem.Element("failure"); if (failure != null) { var msg = failure.Element("message"); if (msg != null) { result.Message = (string)msg; } var stack = failure.Element("stack-trace"); if (stack != null) { result.StackTrace = (string)stack; } } switch ((string)elem.Attribute("result")) { case "Error": case "Failure": result.Status = ResultStatus.Failure; break; case "Success": result.Status = ResultStatus.Success; break; case "Ignored": result.Status = ResultStatus.Ignored; break; default: result.Status = ResultStatus.Inconclusive; break; } if (elem.Name == "test-suite") { // nunitlite does not emit <test-suite type="Namespace" elements so we need to fake // them by deconstructing the full type name and emitting the suite started events manually var names = new List <string> (); if (!macunitStyle || (string)elem.Attribute("type") == "Assembly") { names.Add("<root>"); } else { names.AddRange(elem.Attribute("name").Value.Split('.')); } for (int i = 0; i < names.Count; i++) { listener.SuiteStarted(testPrefix + string.Join(".", names.Take(i + 1))); } var name = (string)elem.Attribute("type") == "Assembly" ? "<root>" : (string)elem.Attribute("name"); var cts = elem.Element("results"); if (cts != null) { foreach (var ct in cts.Elements()) { var r = ReportXmlResult(listener, ct, name != "<root>" ? testPrefix + name + "." : "", macunitStyle); result.Add(r); } } for (int i = 0; i < names.Count; i++) { listener.SuiteFinished(testPrefix + string.Join(".", names.Take(i + 1)), result); } } else { string name = (string)elem.Attribute("name"); switch (result.Status) { case ResultStatus.Success: result.Passed++; break; case ResultStatus.Failure: result.Failures++; break; case ResultStatus.Ignored: result.Ignored++; break; case ResultStatus.Inconclusive: result.Inconclusive++; break; } listener.TestStarted(name); listener.TestFinished(name, result); } return(result); }
UnitTestResult ReportXmlResult (IRemoteEventListener listener, XElement elem, string testPrefix) { UnitTestResult result = new UnitTestResult (); var time = (string)elem.Attribute ("time"); if (time != null) result.Time = TimeSpan.FromSeconds (double.Parse (time, CultureInfo.InvariantCulture)); result.TestDate = DateTime.Now; var reason = elem.Element ("reason"); if (reason != null) result.Message = (string) reason; var failure = elem.Element ("failure"); if (failure != null) { var msg = failure.Element ("message"); if (msg != null) result.Message = (string)msg; var stack = failure.Element ("stack-trace"); if (stack != null) result.StackTrace = (string)stack; } switch ((string)elem.Attribute ("result")) { case "Error": case "Failure": result.Status = ResultStatus.Failure; break; case "Success": result.Status = ResultStatus.Success; break; case "Ignored": result.Status = ResultStatus.Ignored; break; default: result.Status = ResultStatus.Inconclusive; break; } if (elem.Name == "test-suite") { var name = (string)elem.Attribute ("type") == "Assembly" ? "<root>" : (string) elem.Attribute ("name"); listener.SuiteStarted (testPrefix + name); var cts = elem.Element ("results"); if (cts != null) { foreach (var ct in cts.Elements ()) { var r = ReportXmlResult (listener, ct, name != "<root>" ? testPrefix + name + "." : ""); result.Add (r); } } listener.SuiteFinished (testPrefix + name, result); } else { string name = (string)elem.Attribute ("name"); switch (result.Status) { case ResultStatus.Success: result.Passed++; break; case ResultStatus.Failure: result.Failures++; break; case ResultStatus.Ignored: result.Ignored++; break; case ResultStatus.Inconclusive: result.Inconclusive++; break; } listener.TestStarted (name); listener.TestFinished (name, result); } return result; }
public EventListenerWrapper (IRemoteEventListener wrapped) { this.wrapped = wrapped; }
UnitTestResult ReportXmlResult(IRemoteEventListener listener, XElement elem, string testPrefix) { UnitTestResult result = new UnitTestResult(); var time = (string)elem.Attribute("time"); if (time != null) { result.Time = TimeSpan.FromSeconds(double.Parse(time, CultureInfo.InvariantCulture)); } result.TestDate = DateTime.Now; var reason = elem.Element("reason"); if (reason != null) { result.Message = (string)reason; } var failure = elem.Element("failure"); if (failure != null) { var msg = failure.Element("message"); if (msg != null) { result.Message = (string)msg; } var stack = failure.Element("stack-trace"); if (stack != null) { result.StackTrace = (string)stack; } } switch ((string)elem.Attribute("result")) { case "Error": case "Failure": result.Status = ResultStatus.Failure; break; case "Success": result.Status = ResultStatus.Success; break; case "Ignored": result.Status = ResultStatus.Ignored; break; default: result.Status = ResultStatus.Inconclusive; break; } if (elem.Name == "test-suite") { var name = (string)elem.Attribute("type") == "Assembly" ? "<root>" : (string)elem.Attribute("name"); listener.SuiteStarted(testPrefix + name); var cts = elem.Element("results"); if (cts != null) { foreach (var ct in cts.Elements()) { var r = ReportXmlResult(listener, ct, name != "<root>" ? testPrefix + name + "." : ""); result.Add(r); } } listener.SuiteFinished(testPrefix + name, result); } else { string name = (string)elem.Attribute("name"); switch (result.Status) { case ResultStatus.Success: result.Passed++; break; case ResultStatus.Failure: result.Failures++; break; case ResultStatus.Ignored: result.Ignored++; break; case ResultStatus.Inconclusive: result.Inconclusive++; break; } listener.TestStarted(name); listener.TestFinished(name, result); } return(result); }
public DefaultExecutionVisitor(IRemoteEventListener executionListener) { this.executionListener = executionListener; }