/// <summary> /// Runs the async load test info. /// </summary> /// <returns>The async load test info.</returns> /// <param name="cache">Cache.</param> /// <remarks> /// It loads the test case info from cache if there is something in the cache. /// /// Otherwise, the test case info is queried from xunit, by executing a separate process of <seealso cref="XUnitTestRunner"/> /// with MonoDevelop built-in .NET remoting helper. /// /// To debug, the .NET remoting part can be commented out, and replaced with direct calls to <seealso cref="XUnitTestRunner"/>. /// </remarks> void RunAsyncLoadTestInfo(XUnitTestInfoCache cache) { while (true) { XUnitAssemblyTestSuite testSuite; lock (loadQueue) { if (loadQueue.Count == 0) { if (!Monitor.Wait(loadQueue, 5000, true)) { isRunning = false; return; } } testSuite = loadQueue.Dequeue(); } XUnitTestInfo testInfo; try { // If the information is cached in a file and it is up to date information, // there is no need to parse again the assembly. if (cache.Exists) { cache.ReadFromDisk(); testInfo = cache.GetTestInfo(); if (testInfo != null) { testSuite.OnTestSuiteLoaded(testInfo); continue; } } #if EASY_DEBUGGING var runner = new XUnitRunner.XUnitRunner(); testInfo = runner.GetTestInfo(testSuite.AssemblyPath, testSuite.SupportAssemblies.ToArray()); testSuite.OnTestSuiteLoaded(testInfo); #else using (var runner = new ExternalTestRunner()) { runner.Connect(XUnitVersion.XUnit2).Wait(); testInfo = runner.GetTestInfo(testSuite.AssemblyPath, testSuite.SupportAssemblies.ToList()).Result; testSuite.OnTestSuiteLoaded(testInfo); } #endif } catch (Exception ex) { LoggingService.LogError(ex.ToString()); } } }
/// <summary> /// Run the specified testCases, rootSuite, test, context and reportToMonitor. /// </summary> /// <param name="testCases">Test cases.</param> /// <param name="rootSuite">Root suite.</param> /// <param name="test">Test.</param> /// <param name="context">Context.</param> /// <param name="reportToMonitor">Report to monitor.</param> /// <remarks> /// This is actual the code that executes the test cases. /// /// It uses the MonoDevelop built-in .NET remoting helper to execute the code of <seealso cref="XUnitTestRunner"/> in a separate process. /// /// If any debugging is required, simply comment out the remoting part, and call <seealso cref="XUnitTestRunner"/> directly, /// so that the code executes inside MonoDevelop. /// </remarks> UnitTestResult Run(List <XUnitTestCase> testCases, XUnitAssemblyTestSuite rootSuite, IExecutableTest test, TestContext context, bool reportToMonitor = true) { #if EASY_DEBUGGING using (var session = test.CreateExecutionSession(reportToMonitor)) { var runner = new XUnitRunner.XUnitRunner(); var localTestMonitor = new LocalTestMonitor(context, rootSuite, rootSuite.Name, false); string[] nameFilter = new string[testCases.Count]; for (var i = 0; i < testCases.Count; ++i) { nameFilter[i] = testCases[i].TestInfo.Id; } var path = rootSuite.AssemblyPath; runner.Execute(path, nameFilter, localTestMonitor); return(session.Result); } #else using (var session = test.CreateExecutionSession(reportToMonitor)) { using (var runner = new ExternalTestRunner()) { runner.Connect(XUnitVersion.XUnit2, context.ExecutionContext.ExecutionHandler).Wait(); var localTestMonitor = new LocalTestMonitor(context, rootSuite, rootSuite.Name, false); string[] nameFilter = new string[testCases.Count]; for (var i = 0; i < testCases.Count; ++i) { nameFilter[i] = testCases[i].TestInfo.Id; } var path = rootSuite.AssemblyPath; var supportAssemblies = new List <string>(); var crashLogFile = Path.GetTempFileName(); runner.Run(localTestMonitor, nameFilter, path, "", supportAssemblies, null, null, crashLogFile).Wait(); } return(session.Result); } #endif }
/// <summary> /// Run the specified testCases, rootSuite, test, context and reportToMonitor. /// </summary> /// <param name="testCases">Test cases.</param> /// <param name="rootSuite">Root suite.</param> /// <param name="test">Test.</param> /// <param name="context">Context.</param> /// <param name="reportToMonitor">Report to monitor.</param> /// <remarks> /// This is actual the code that executes the test cases. /// /// It uses the MonoDevelop built-in .NET remoting helper to execute the code of <seealso cref="XUnitTestRunner"/> in a separate process. /// /// If any debugging is required, simply comment out the remoting part, and call <seealso cref="XUnitTestRunner"/> directly, /// so that the code executes inside MonoDevelop. /// </remarks> UnitTestResult Run(List <XUnitTestCase> testCases, XUnitAssemblyTestSuite rootSuite, IExecutableTest test, TestContext context, bool reportToMonitor = true) { #if EASY_DEBUGGING using (var session = test.CreateExecutionSession(reportToMonitor)) { var runner = new XUnitRunner.XUnitRunner(); var localTestMonitor = new LocalTestMonitor(context, rootSuite, rootSuite.Name, false); string[] nameFilter = new string[testCases.Count]; for (var i = 0; i < testCases.Count; ++i) { nameFilter[i] = testCases[i].TestInfo.Id; } var path = rootSuite.AssemblyPath; runner.Execute(path, nameFilter, localTestMonitor); return(session.Result); } #else using (var session = test.CreateExecutionSession(reportToMonitor)) { using (var runner = new ExternalTestRunner()) { runner.Connect(XUnitVersion.XUnit2, context.ExecutionContext.ExecutionHandler).Wait(); var localTestMonitor = new LocalTestMonitor(context, rootSuite, rootSuite.Name, false); string[] nameFilter = new string[testCases.Count]; for (var i = 0; i < testCases.Count; ++i) { nameFilter[i] = testCases[i].TestInfo.Id; } var path = rootSuite.AssemblyPath; var supportAssemblies = new List <string>(); RunData rd = new RunData(); rd.Runner = runner; rd.LocalMonitor = localTestMonitor; var cancelReg = context.Monitor.CancellationToken.Register(rd.Cancel); UnitTestResult result; var crashLogFile = Path.GetTempFileName(); try { context.Monitor.CancellationToken.ThrowIfCancellationRequested(); runner.Run(localTestMonitor, nameFilter, path, "", supportAssemblies, null, null, crashLogFile).Wait(); } catch (Exception ex) { if (!localTestMonitor.Canceled) { LoggingService.LogError(ex.ToString()); result = UnitTestResult.CreateFailure(ex); } else { result = UnitTestResult.CreateFailure(GettextCatalog.GetString("Canceled"), null); } } finally { // Dispose the runner before the console, to make sure the console is available until the runner is disposed. runner.Dispose(); cancelReg.Dispose(); File.Delete(crashLogFile); } } return(session.Result); } #endif }