public TestExecutionTask(ITestEngineRunner runner, ITestEventListener listener, TestFilter filter, bool disposeRunner) { _disposeRunner = disposeRunner; _filter = filter; _listener = listener; _runner = runner; }
/// <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> /// Start a run of the tests in the loaded TestPackage. The tests are run /// asynchronously 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> public void StartRun(ITestEventListener listener, TestFilter filter) { if (_runner == null) throw new InvalidOperationException("RemoteTestAgent: StartRun called before Load"); _runner.StartRun(listener, filter); }
/// <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 TestEngineResult giving the result of the test execution. /// </returns> protected override TestEngineResult RunTests(ITestEventListener listener, TestFilter filter) { var results = new List<TestEngineResult>(); bool disposeRunners = TestPackage.GetSetting(PackageSettings.DisposeRunners, false); foreach (ITestEngineRunner runner in _runners) { results.Add(runner.Run(listener, filter)); if (disposeRunners) runner.Dispose(); } if (disposeRunners) _runners.Clear(); TestEngineResult result = ResultHelper.Merge(results); return IsProjectPackage(TestPackage) ? result.MakePackageResult(TestPackage.Name, TestPackage.FullName) : result; }
/// <summary> /// Run the tests in the loaded TestPackage. /// </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) { var result = new TestEngineResult(); foreach (IFrameworkDriver driver in _drivers) { result.Add(driver.Run(listener, filter.Text)); } if (IsProjectPackage(TestPackage)) result = result.MakePackageResult(TestPackage.Name, TestPackage.FullName); if (_assemblyResolver != null) { var packages = TestPackage.SubPackages; if (packages.Count == 0) packages.Add(TestPackage); foreach (var package in packages) _assemblyResolver.RemovePathFromFile(package.FullName); } 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> /// Start a run of the tests in the loaded TestPackage, returning immediately. /// The tests are run asynchronously 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> protected virtual void RunTestsAsynchronously(ITestEventListener listener, TestFilter filter) { using (var worker = new BackgroundWorker()) { worker.DoWork += (s, ea) => RunTests(listener, filter); worker.RunWorkerAsync(); } }
/// <summary> /// Start a run of the tests in the loaded TestPackage. The tests are run /// asynchronously and the listener interface is notified as it progresses. /// </summary> /// <param name="listener">The listener that is notified as the run progresses</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns></returns> ITestRun ITestRunner.RunAsync(ITestEventListener listener, TestFilter filter) { return RunAsync(listener, filter); }
/// <summary> /// Start a run of the tests in the loaded TestPackage. The tests are run /// asynchronously and the listener interface is notified as it progresses. /// </summary> /// <param name="listener">The listener that is notified as the run progresses</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns></returns> ITestRun ITestRunner.RunAsync(ITestEventListener listener, TestFilter filter) { return(RunAsync(listener, filter)); }
public string Run(ITestEventListener listener, string filter) { throw new NotImplementedException(); }
/// <summary> /// Run the tests in the loaded TestPackage. /// </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 abstract TestEngineResult RunTests(ITestEventListener listener, TestFilter filter);
/// <summary> /// Start a run of the tests in the loaded TestPackage. The tests are run /// asynchronously 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> public void StartRun(ITestEventListener listener, TestFilter filter) { RunAsync(listener, filter); }
/// <summary> /// Run the tests in the TestPackage, loading the package /// if this has not already been done. /// </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(RunTests(listener, filter)); }
public TestEngineResult Run(ITestEventListener listener, TestFilter filter) { SendCommandMessage("Run", filter); return(TestRunResult(listener)); }
/// <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) { _workItemTracker.Clear(); _eventDispatcher.Listeners.Clear(); _eventDispatcher.Listeners.Add(_workItemTracker); if (listener != null) { _eventDispatcher.Listeners.Add(listener); } #if !NETSTANDARD1_6 foreach (var extension in _extensionService.GetExtensions <ITestEventListener>()) { _eventDispatcher.Listeners.Add(extension); } #endif IsTestRunning = true; string clrVersion; string engineVersion; #if !NETSTANDARD1_6 clrVersion = Environment.Version.ToString(); engineVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); #else clrVersion = Microsoft.DotNet.InternalAbstractions.RuntimeEnvironment.GetRuntimeIdentifier(); engineVersion = typeof(MasterTestRunner).GetTypeInfo().Assembly.GetName().Version.ToString(); #endif var startTime = DateTime.UtcNow; long startTicks = Stopwatch.GetTimestamp(); try { var startRunNode = XmlHelper.CreateTopLevelElement("start-run"); startRunNode.AddAttribute("count", CountTests(filter).ToString()); startRunNode.AddAttribute("start-time", XmlConvert.ToString(startTime, "u")); startRunNode.AddAttribute("engine-version", engineVersion); startRunNode.AddAttribute("clr-version", clrVersion); #if !NETSTANDARD1_6 InsertCommandLineElement(startRunNode); #endif _eventDispatcher.OnTestEvent(startRunNode.OuterXml); TestEngineResult result = PrepareResult(GetEngineRunner().Run(_eventDispatcher, filter)).MakeTestRunResult(TestPackage); // These are inserted in reverse order, since each is added as the first child. InsertFilterElement(result.Xml, filter); #if !NETSTANDARD1_6 InsertCommandLineElement(result.Xml); #endif result.Xml.AddAttribute("engine-version", engineVersion); result.Xml.AddAttribute("clr-version", clrVersion); 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); } catch (Exception ex) { IsTestRunning = false; var resultXml = XmlHelper.CreateTopLevelElement("test-run"); resultXml.AddAttribute("id", TestPackage.ID); resultXml.AddAttribute("result", "Failed"); resultXml.AddAttribute("label", "Error"); resultXml.AddAttribute("engine-version", engineVersion); resultXml.AddAttribute("clr-version", clrVersion); double duration = (double)(Stopwatch.GetTimestamp() - startTicks) / Stopwatch.Frequency; resultXml.AddAttribute("start-time", XmlConvert.ToString(startTime, "u")); resultXml.AddAttribute("end-time", XmlConvert.ToString(DateTime.UtcNow, "u")); resultXml.AddAttribute("duration", duration.ToString("0.000000", NumberFormatInfo.InvariantInfo)); _eventDispatcher.OnTestEvent(resultXml.OuterXml); _eventDispatcher.OnTestEvent($"<unhandled-exception message='{ex.Message}' />"); return(new TestEngineResult(resultXml)); } }
/// <summary> /// Run the tests in a loaded TestPackage. The explicit /// implementation returns an ITestEngineResult for use /// by external clients. /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>An XmlNode giving the result of the test execution</returns> public XmlNode Run(ITestEventListener listener, TestFilter filter) { return(RunTests(listener, filter).Xml); }
/// <summary> /// Run the tests in the TestPackage, loading the package /// if this has not already been done. /// </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) { EnsurePackageIsLoaded(); return RunTests(listener, filter); }
/// <summary> /// Run the tests in the TestPackage, loading the package /// if this has not already been done. /// </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) { EnsurePackageIsLoaded(); return(RunTests(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> 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. result.Xml.InsertFilterElement(filter); result.Xml.InsertSettingsElement(EffectiveSettings); result.Xml.InsertCommandLineElement(); 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; }
/// <summary> /// Start a run of the tests in the TestPackage. The tests are run /// asynchronously and the listener interface is notified as it progresses. /// Loads the TestPackage if not already loaded. /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> public void StartRun(ITestEventListener listener, TestFilter filter) { EnsurePackageIsLoaded(); RunTestsAsynchronously(listener, filter); }
public string Run(ITestEventListener listener, TestFilter filter) { return(string.Format(RUN_RESULT_FORMAT, _name, _fullname, _message)); }
/// <summary> /// Run the tests in the loaded TestPackage. /// </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) { var result = new TestEngineResult(); foreach (IFrameworkDriver driver in _drivers) result.Add(driver.Run(listener, filter.Text)); if (IsProjectPackage(TestPackage)) result = result.MakePackageResult(TestPackage.Name, TestPackage.FullName); return result; }
public RunTestsCallbackHandler(ITestEventListener listener) { _listener = listener ?? new NullListener(); }
/// <summary> /// Executes the tests in an assembly. /// </summary> /// <param name="listener">An ITestEventHandler that receives progress notices</param> /// <param name="filter">A filter that controls which tests are executed</param> /// <returns>An Xml string representing the result</returns> public string Run(ITestEventListener listener, string filter) { CheckLoadWasCalled(); CallbackHandler handler = new RunTestsCallbackHandler(listener); log.Info("Running {0} - see separate log file", Path.GetFileName(_testAssemblyPath)); CreateObject(RUN_ACTION, _frameworkController, filter, handler); return handler.Result; }
/// <summary> /// Run the tests in a loaded TestPackage. The explicit /// implementation returns an ITestEngineResult for use /// by external clients. /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>An XmlNode giving the result of the test execution</returns> public XmlNode Run(ITestEventListener listener, TestFilter filter) { return(PrepareResult(RunTests(listener, filter)).Xml); }
/// <summary> /// Start a run of the tests in the loaded TestPackage. The tests are run /// asynchronously and the listener interface is notified as it progresses. /// </summary> /// <param name="listener">The listener that is notified as the run progresses</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns></returns> public ITestRun RunAsync(ITestEventListener listener, TestFilter filter) { return(RunTestsAsync(listener, filter)); }
public string Run(ITestEventListener listener, string filter) { return string.Format(RUN_RESULT_FORMAT, TestID, _name, _fullname, _message); }
/// <summary> /// Start a run of the tests in the loaded TestPackage. The tests are run /// asynchronously 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 <see cref="AsyncTestEngineResult"/> that will provide the result of the test execution</returns> public AsyncTestEngineResult RunAsync(ITestEventListener listener, TestFilter filter) { return(_runner.RunAsync(listener, filter)); }
/// <summary> /// Start a run of the tests in the loaded TestPackage. The tests are run /// asynchronously and the listener interface is notified as it progresses. /// </summary> /// <param name="listener">The listener that is notified as the run progresses</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns></returns> ITestRun ITestRunner.RunAsync(ITestEventListener listener, TestFilter filter) { var testRun = new TestRun(this); testRun.Start(listener, filter); return testRun; }
/// <summary> /// Start a run of the tests in the loaded TestPackage, returning immediately. /// The tests are run asynchronously 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 ITestRun that will provide the result of the test execution</returns> protected override ITestRun RunTestsAsync(ITestEventListener listener, TestFilter filter) { return _remoteRunner.RunAsync(listener, filter); }
/// <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 TestEngineResult giving the result of the test execution. /// </returns> protected override TestEngineResult RunTests(ITestEventListener listener, TestFilter filter) { var results = new List<TestEngineResult>(); bool disposeRunners = TestPackage.GetSetting(EnginePackageSettings.DisposeRunners, false); if (LevelOfParallelism <= 1) { foreach (ITestEngineRunner runner in _runners) { results.Add(runner.Run(listener, filter)); if (disposeRunners) runner.Dispose(); } } else { var workerPool = new ParallelTaskWorkerPool(LevelOfParallelism); var tasks = new List<TestExecutionTask>(); foreach (ITestEngineRunner runner in _runners) { var task = new TestExecutionTask(runner, listener, filter, disposeRunners); tasks.Add(task); workerPool.Enqueue(task); } workerPool.Start(); workerPool.WaitAll(); foreach (var task in tasks) results.Add(task.Result()); } if (disposeRunners) _runners.Clear(); TestEngineResult result = ResultHelper.Merge(results); return IsProjectPackage(TestPackage) ? result.MakePackageResult(TestPackage.Name, TestPackage.FullName) : result; }
public XmlNode Run (ITestEventListener listener, string[] nameFilter, string path, string suiteName, string[] supportAssemblies, string testRunnerType, string testRunnerAssembly) { InitSupportAssemblies (supportAssemblies); TestFilter filter = TestFilter.Empty; if (nameFilter != null && nameFilter.Length > 0) filter = CreateTestFilter (nameFilter); ITestRunner tr = null; if (!string.IsNullOrEmpty (testRunnerType)) { Type runnerType; if (string.IsNullOrEmpty (testRunnerAssembly)) runnerType = Type.GetType (testRunnerType, true); else { var asm = Assembly.LoadFrom (testRunnerAssembly); runnerType = asm.GetType (testRunnerType); } tr = (ITestRunner)Activator.CreateInstance (runnerType); } TestPackage package = CreatePackage (path); if (tr == null) tr = engine.GetRunner (package); return tr.Run (listener, filter); }
/// <summary> /// Start a run of the tests in the loaded TestPackage. The tests are run /// asynchronously 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>An <see cref="ITestRun"/> that will provide the result of the test execution</returns> public ITestRun RunAsync(ITestEventListener listener, TestFilter filter) { EnsurePackageIsLoaded(); return RunTestsAsync(listener, filter); }
internal string RunInternal(ITestEventListener listener, TestFilter filter) { return _runner.Run(listener, filter).OuterXml; }
/// <summary> /// Run the tests in a loaded TestPackage. The explicit /// implementation returns an ITestEngineResult for use /// by external clients. /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>An XmlNode giving the result of the test execution</returns> XmlNode ITestRunner.Run(ITestEventListener listener, TestFilter filter) { return Run(listener, filter).Xml; }
/// <summary> /// Start a run of the tests in the loaded TestPackage. The tests are run /// asynchronously 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 <see cref="ITestRun"/> that will provide the result of the test execution</returns> public ITestRun RunAsync(ITestEventListener listener, TestFilter filter) { if (_runner == null) throw new InvalidOperationException("RemoteTestAgent: RunAsync called before Load"); return _runner.RunAsync(listener, filter); }
/// <summary> /// Run the tests in the TestPackage, loading the package /// if this has not already been done. /// </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 RunTests(listener, filter); }
public string Run(ITestEventListener listener, string filter) { if (_runner.Test == null) return String.Format(LOAD_RESULT_FORMAT, TestID, _name, _fullname, "Error loading test"); ITestFilter v2Filter = CreateNUnit2TestFilter(filter); var result = _runner.Run(new TestEventAdapter(listener), v2Filter, false, LoggingThreshold.Off); return result.ToXml(true).OuterXml; }
/// <summary> /// Run the tests in a loaded TestPackage. The explicit /// implementation returns an ITestEngineResult for use /// by external clients. /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>An XmlNode giving the result of the test execution</returns> XmlNode ITestRunner.Run(ITestEventListener listener, TestFilter filter) { return(Run(listener, filter).Xml); }
/// <summary> /// Start a run of the tests in the loaded TestPackage, returning immediately. /// The tests are run asynchronously 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>An <see cref="AsyncTestEngineResult"/> that will provide the result of the test execution</returns> protected virtual AsyncTestEngineResult RunTestsAsync(ITestEventListener listener, TestFilter filter) { var testRun = new AsyncTestEngineResult(); using (var worker = new BackgroundWorker()) { worker.DoWork += (s, ea) => { var result = RunTests(listener, filter); testRun.SetResult(result); }; worker.RunWorkerAsync(); } return testRun; }
/// <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> /// Start a run of the tests in the loaded TestPackage. The tests are run /// asynchronously 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>An <see cref="AsyncTestEngineResult"/> that will provide the result of the test execution</returns> public AsyncTestEngineResult RunAsync(ITestEventListener listener, TestFilter filter) { return RunTestsAsync(listener, filter); }
/// <summary> /// Start a run of the tests in the loaded TestPackage, returning immediately. /// The tests are run asynchronously 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>An AsyncTestRun that will provide the result of the test execution</returns> protected override AsyncTestEngineResult RunTestsAsync(ITestEventListener listener, TestFilter filter) { try { return _remoteRunner.RunAsync(listener, filter); } catch (Exception e) { log.Error("Failed to run remote tests {0}", e.Message); var result = new AsyncTestEngineResult(); result.SetResult(CreateFailedResult(e)); return result; } }
public RunTestsCallbackHandler(ITestEventListener listener) { // TODO: Move this substitution into the framework? this.listener = listener ?? new NullListener(); }