/// <summary> /// Start asynchronous execution of a test. /// </summary> /// <param name="listener">The ITestEventListener to use for this run</param> /// <param name="filter">The TestFilter to use for this run</param> public void Start(ITestEventListener listener, TestFilter filter) { _worker.DoWork += (s, ea) => _result = _runner.Run(listener, filter); _worker.RunWorkerAsync(); }
/// <summary> /// Run the tests in the loaded TestPackage and return a test result. The tests /// are run synchronously and the listener interface is notified as it progresses. /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>A TestEngineResult giving the result of the test execution</returns> protected override TestEngineResult RunTests(ITestEventListener listener, TestFilter filter) { IsTestRunning = true; if (listener != null) { listener.OnTestEvent(string.Format("<start-run count='{0}'/>", CountTestCases(filter))); } DateTime startTime = DateTime.UtcNow; long startTicks = Stopwatch.GetTimestamp(); TestEngineResult result = _realRunner.Run(listener, filter).Aggregate("test-run", TestPackage.Name, TestPackage.FullName); result.Xml.InsertEnvironmentElement(); double duration = (double)(Stopwatch.GetTimestamp() - startTicks) / Stopwatch.Frequency; result.Xml.AddAttribute("start-time", XmlConvert.ToString(startTime, "u")); result.Xml.AddAttribute("end-time", XmlConvert.ToString(DateTime.UtcNow, "u")); result.Xml.AddAttribute("duration", duration.ToString("0.000000", NumberFormatInfo.InvariantInfo)); IsTestRunning = false; if (listener != null) { listener.OnTestEvent(result.Xml.OuterXml); } return(result); }
public void Execute() { _result = _runner.Run(_listener, _filter); if (_disposeRunner) { _runner.Dispose(); } }
/// <summary> /// Run the tests in the loaded TestPackage and return a test result. The tests /// are run synchronously and the listener interface is notified as it progresses. /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>A TestEngineResult giving the result of the test execution</returns> public TestEngineResult Run(ITestEventListener listener, TestFilter filter) { if (_runner == null) { throw new InvalidOperationException("RemoteTestAgent: Run called before Load"); } return(_runner.Run(listener, filter)); }
private void CommandLoop() { bool keepRunning = true; var socketReader = new SocketReader(_clientSocket, new BinarySerializationProtocol()); while (keepRunning) { var command = socketReader.GetNextMessage <CommandMessage>(); switch (command.CommandName) { case "CreateRunner": var package = (TestPackage)command.Arguments[0]; _runner = CreateRunner(package); break; case "Load": SendResult(_runner.Load()); break; case "Reload": SendResult(_runner.Reload()); break; case "Unload": _runner.Unload(); break; case "Explore": var filter = (TestFilter)command.Arguments[0]; SendResult(_runner.Explore(filter)); break; case "CountTestCases": filter = (TestFilter)command.Arguments[0]; SendResult(_runner.CountTestCases(filter)); break; case "Run": filter = (TestFilter)command.Arguments[0]; SendResult(_runner.Run(this, filter)); break; case "RunAsync": filter = (TestFilter)command.Arguments[0]; _runner.RunAsync(this, filter); break; case "Stop": keepRunning = false; break; } } Stop(); }
/// <summary> /// Run the tests in a loaded TestPackage /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>A TestResult giving the result of the test execution</returns> protected override TestEngineResult RunTests(ITestEventListener listener, TestFilter filter) { try { return(_remoteRunner.Run(listener, filter)); } catch (Exception e) { log.Error("Failed to run remote tests {0}", e.Message); return(CreateFailedResult(e)); } }
/// <summary> /// Run the tests in a loaded TestPackage /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>A TestResult giving the result of the test execution</returns> protected override TestEngineResult RunTests(ITestEventListener listener, TestFilter filter) { log.Info("Running " + TestPackage.Name); try { var result = _remoteRunner.Run(listener, filter); log.Info("Done running " + TestPackage.Name); return(result); } catch (Exception e) { log.Error("Failed to run remote tests {0}", e.Message); return(CreateFailedResult(e)); } }
/// <summary> /// Run the tests in the loaded TestPackage and return a test result. The tests /// are run synchronously and the listener interface is notified as it progresses. /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>A TestEngineResult giving the result of the test execution</returns> private TestEngineResult RunTests(ITestEventListener listener, TestFilter filter) { var eventDispatcher = new TestEventDispatcher(); if (listener != null) { eventDispatcher.Listeners.Add(listener); } #if !NETSTANDARD1_6 foreach (var extension in _extensionService.GetExtensions <ITestEventListener>()) { eventDispatcher.Listeners.Add(extension); } #endif IsTestRunning = true; eventDispatcher.OnTestEvent(string.Format("<start-run count='{0}'/>", CountTests(filter))); DateTime startTime = DateTime.UtcNow; long startTicks = Stopwatch.GetTimestamp(); TestEngineResult result = _engineRunner.Run(eventDispatcher, filter).Aggregate("test-run", TestPackage.Name, TestPackage.FullName); // These are inserted in reverse order, since each is added as the first child. InsertFilterElement(result.Xml, filter); #if !NETSTANDARD1_6 InsertCommandLineElement(result.Xml); result.Xml.AddAttribute("engine-version", Assembly.GetExecutingAssembly().GetName().Version.ToString()); result.Xml.AddAttribute("clr-version", Environment.Version.ToString()); #else result.Xml.AddAttribute("engine-version", typeof(MasterTestRunner).GetTypeInfo().Assembly.GetName().Version.ToString()); result.Xml.AddAttribute("clr-version", Microsoft.DotNet.InternalAbstractions.RuntimeEnvironment.GetRuntimeIdentifier()); #endif double duration = (double)(Stopwatch.GetTimestamp() - startTicks) / Stopwatch.Frequency; result.Xml.AddAttribute("start-time", XmlConvert.ToString(startTime, "u")); result.Xml.AddAttribute("end-time", XmlConvert.ToString(DateTime.UtcNow, "u")); result.Xml.AddAttribute("duration", duration.ToString("0.000000", NumberFormatInfo.InvariantInfo)); IsTestRunning = false; eventDispatcher.OnTestEvent(result.Xml.OuterXml); return(result); }
/// <summary> /// Run the tests in a loaded TestPackage /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>A TestResult giving the result of the test execution</returns> protected override TestEngineResult RunTests(ITestEventListener listener, TestFilter filter) { log.Info("Running " + TestPackage.Name); try { CreateAgentAndRunnerIfNeeded(); var result = _remoteRunner.Run(listener, filter); log.Info("Done running " + TestPackage.Name); return(result); } catch (Exception e) { log.Error("Failed to run remote tests {0}", ExceptionHelper.BuildMessageAndStackTrace(e)); return(CreateFailedResult(e)); } }
public void Execute() { _hasExecuted = true; try { _result = _runner.Run(_listener, _filter); } finally { try { if (_disposeRunner) _runner.Dispose(); } catch (Exception e) { _unloadException = e; } } }
public void Run(string filePath, string expectedType) { // We only create runners for subpackages var package = new TestPackage(filePath).SubPackages[0]; ITestEngineRunner runner = CreateRunner(package); var result = runner.Run(new NullListener(), TestFilter.Empty).Xml; Assert.That(result.Name, Is.EqualTo("test-suite")); Assert.That(result.GetAttribute("id"), Is.EqualTo(package.ID)); Assert.That(result.GetAttribute("name"), Is.EqualTo(filePath)); Assert.That(result.GetAttribute("fullname"), Is.EqualTo(Path.GetFullPath(filePath))); Assert.That(result.GetAttribute("type"), Is.EqualTo(expectedType)); Assert.That(result.GetAttribute("runstate"), Is.EqualTo(_expectedRunState)); Assert.That(result.GetAttribute("testcasecount"), Is.EqualTo("0")); Assert.That(GetSkipReason(result), Is.EqualTo(_expectedReason)); Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests"); Assert.That(result.GetAttribute("result"), Is.EqualTo(_expectedResult)); Assert.That(result.GetAttribute("label"), Is.EqualTo(_expectedLabel)); Assert.That(result.SelectSingleNode("reason/message").InnerText, Is.EqualTo(_expectedReason)); }
/// <summary> /// Run the tests in the loaded TestPackage and return a test result. The tests /// are run synchronously and the listener interface is notified as it progresses. /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>A TestEngineResult giving the result of the test execution</returns> protected override TestEngineResult RunTests(ITestEventListener listener, TestFilter filter) { IsTestRunning = true; if (listener != null) { listener.OnTestEvent(string.Format("<start-run count='{0}'/>", CountTestCases(filter))); } DateTime startTime = DateTime.UtcNow; long startTicks = Stopwatch.GetTimestamp(); TestEngineResult result = _realRunner.Run(listener, filter).Aggregate("test-run", TestPackage.Name, TestPackage.FullName); // These are inserted in reverse order, since each is added as the first child. InsertFilterElement(result.Xml, filter); InsertCommandLineElement(result.Xml); result.Xml.AddAttribute("engine-version", Assembly.GetExecutingAssembly().GetName().Version.ToString()); result.Xml.AddAttribute("clr-version", Environment.Version.ToString()); double duration = (double)(Stopwatch.GetTimestamp() - startTicks) / Stopwatch.Frequency; result.Xml.AddAttribute("start-time", XmlConvert.ToString(startTime, "u")); result.Xml.AddAttribute("end-time", XmlConvert.ToString(DateTime.UtcNow, "u")); result.Xml.AddAttribute("duration", duration.ToString("0.000000", NumberFormatInfo.InvariantInfo)); IsTestRunning = false; if (listener != null) { listener.OnTestEvent(result.Xml.OuterXml); } return(result); }
/// <summary> /// Run the tests in a loaded TestPackage /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>A TestResult giving the result of the test execution</returns> protected override TestEngineResult RunTests(ITestEventListener listener, TestFilter filter) { return(_remoteRunner.Run(listener, filter)); }
/// <summary> /// Run the tests in the loaded TestPackage and return a test result. The tests /// are run synchronously and the listener interface is notified as it progresses. /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>A TestEngineResult giving the result of the test execution</returns> public TestEngineResult Run(ITestEventListener listener, TestFilter filter) { return(_runner.Run(listener, filter)); }
/// <summary> /// Run the tests in the loaded TestPackage and return a test result. The tests /// are run synchronously and the listener interface is notified as it progresses. /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>A TestEngineResult giving the result of the test execution</returns> public TestEngineResult Run(ITestEventHandler listener, TestFilter filter) { return(runner == null ? null : runner.Run(listener, filter)); }