Esempio n. 1
0
 private void TryStopRunner(global::NUnit.Engine.ITestRunner testRunner)
 {
     // Really hacky but sometimes it fail..
     for (int n = 0; n < 3; n++)
     {
         try
         {
             testRunner.StopRun(true);
             testRunner.Unload();
         }
         catch (Exception)
         {
             Task.Delay(TimeSpan.FromSeconds(1));
         }
     }
 }
Esempio n. 2
0
        public Task <TestSuiteResult> RunTestsAsync(string dllPath)
        {
            return(Task.Run(() =>
            {
                var package = new TestPackage(dllPath);

                using (var engine = new TestEngine())
                {
                    engine.Services.Add(new SettingsService(false));
                    engine.Services.Add(new ExtensionService());
                    engine.Services.Add(new DriverService());
                    engine.Services.Add(new InProcessTestRunnerFactory());
                    engine.Services.Add(new ProjectService());          // +
                    engine.Services.Add(new RuntimeFrameworkService()); // +
                    engine.Services.Add(new TestFilterService());       // +
                    engine.Services.Add(new DomainManager());           // -
                    engine.Services.Add(new ResultService());
                    engine.Services.ServiceManager.StartServices();

                    using (global::NUnit.Engine.ITestRunner runner = engine.GetRunner(package))
                    {
                        try
                        {
                            var filter = TestFilter.Empty;
                            var result = runner.Run(new TestEventDispatcher(), filter);

                            if (result == null)
                            {
                                return TestSuiteResult.Error("No results", TimeSpan.Zero);
                            }

                            runner.Unload();
                            var parsedResults = CreateResult(result);
                            return parsedResults;
                        }
                        catch (Exception ex)
                        {
                            TryStopRunner(runner);
                            return TestSuiteResult.Error($"Unkown nunit error: {ex.Message}", TimeSpan.Zero);
                        }
                    }
                }
            }));
        }