public void Initialize() { var engineX = new TestEngineClass(); InternalEngineCreated?.Invoke(engineX); TestEngine = engineX; }
private static void RunTests(string assemblyPath) { var package = new TestPackage(assemblyPath); var engine = new TestEngine(); var runner = engine.GetRunner(package); XmlNode result = runner.Run(new TestListener(), TestFilter.Empty); string overallResult = result.GetAttribute("result"); Console.WriteLine("Test Run for {0} {1}", assemblyPath, result.GetAttribute("result")); Console.WriteLine(" Passing Tests: {0}", result.GetAttribute("passed")); Console.WriteLine(" Failing Tests: {0}", result.GetAttribute("failed")); Console.WriteLine(" Inconclusive Tests: {0}", result.GetAttribute("inconclusive")); Console.WriteLine(" Skipped Tests: {0}", result.GetAttribute("skipped")); Console.WriteLine(); }
// The Adapter is constructed using the default constructor. // We don't have any info to initialize it until one of the // ITestDiscovery or ITestExecutor methods is called. Each // Discover or Execute method must call this method. protected void Initialize(IDiscoveryContext context, IMessageLogger messageLogger) { TestEngine = new TestEngineClass(); TestLog = new TestLogger(messageLogger); Settings = new AdapterSettings(TestLog); try { Settings.Load(context); TestLog.Verbosity = Settings.Verbosity; } catch (Exception e) { TestLog.Warning("Error initializing RunSettings. Default settings will be used"); TestLog.Warning(e.ToString()); } }
// The Adapter is constructed using the default constructor. // We don't have any info to initialize it until one of the // ITestDiscovery or ITestExecutor methods is called. Each // Discover or Execute method must call this method. protected void Initialize(IDiscoveryContext context, IMessageLogger messageLogger) { var engine = new TestEngineClass(); InternalEngineCreated?.Invoke(engine); TestEngine = engine; TestLog = new TestLogger(messageLogger); Settings = new AdapterSettings(TestLog); TestLog.InitSettings(Settings); try { Settings.Load(context); TestLog.Verbosity = Settings.Verbosity; CheckDirectories(); } catch (Exception e) { TestLog.Warning("Error initializing RunSettings. Default settings will be used"); TestLog.Warning(e.ToString()); } }
public static int Main(string[] args) { AgentId = new Guid(args[0]); AgencyUrl = args[1]; bool pause = false, verbose = false; for (int i = 2; i < args.Length; i++) switch (args[i]) { case "--pause": pause = true; break; case "--verbose": verbose = true; break; } #if DEBUG if (pause) System.Windows.Forms.MessageBox.Show("Attach debugger if desired, then press OK", "NUnit-Agent"); #endif // Create SettingsService early so we know the trace level right at the start SettingsService settingsService = new SettingsService("NUnit30Settings.xml", false); //InternalTrace.Initialize("nunit-agent_%p.log", (InternalTraceLevel)settingsService.GetSetting("Options.InternalTraceLevel", InternalTraceLevel.Default)); //log.Info("Agent process {0} starting", Process.GetCurrentProcess().Id); //log.Info("Running under version {0}, {1}", // Environment.Version, // RuntimeFramework.CurrentFramework.DisplayName); if (verbose) { Console.WriteLine("Agent process {0} starting", Process.GetCurrentProcess().Id); Console.WriteLine("Running under version {0}, {1}", Environment.Version, RuntimeFramework.CurrentFramework.DisplayName); } // Create TestEngine - this program is // conceptually part of the engine and // can access it's internals as needed. TestEngine engine = new TestEngine(); // Custom Service Initialization //log.Info("Adding Services"); engine.Services.Add(settingsService); engine.Services.Add(new ProjectService()); engine.Services.Add(new DomainManager()); engine.Services.Add(new InProcessTestRunnerFactory()); engine.Services.Add(new DriverFactory()); //engine.Services.Add( new TestLoader() ); // Initialize Services //log.Info("Initializing Services"); engine.Services.ServiceManager.InitializeServices(); Channel = ServerUtilities.GetTcpChannel(); //log.Info("Connecting to TestAgency at {0}", AgencyUrl); try { Agency = Activator.GetObject(typeof(ITestAgency), AgencyUrl) as ITestAgency; } catch (Exception ex) { Console.WriteLine("Unable to connect\r\n{0}", ex); //log.Error("Unable to connect", ex); } if (Channel != null) { //log.Info("Starting RemoteTestAgent"); RemoteTestAgent agent = new RemoteTestAgent(AgentId, Agency, engine.Services); try { if (agent.Start()) { //log.Debug("Waiting for stopSignal"); agent.WaitForStop(); //log.Debug("Stop signal received"); } else Console.WriteLine("Failed to start RemoteTestAgent"); //log.Error("Failed to start RemoteTestAgent"); } catch (Exception ex) { //log.Error("Exception in RemoteTestAgent", ex); Console.WriteLine("Exception in RemoteTestAgent", ex); } //log.Info("Unregistering Channel"); try { ChannelServices.UnregisterChannel(Channel); } catch (Exception ex) { //log.Error("ChannelServices.UnregisterChannel threw an exception", ex); Console.WriteLine("ChannelServices.UnregisterChannel threw an exception\r\n{0}", ex); } } if (verbose) Console.WriteLine("Agent process {0} exiting", Process.GetCurrentProcess().Id); //log.Info("Agent process {0} exiting", Process.GetCurrentProcess().Id); //InternalTrace.Close(); return 0; }
// The Adapter is constructed using the default constructor. // We don't have any info to initialize it until one of the // ITestDiscovery or ITestExecutor methods is called. The // each Discover or Execute method must call this method. protected virtual void Initialize(IMessageLogger messageLogger) { Verbosity = 0; // In case we throw below AdapterVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); try { var registry = RegistryCurrentUser.OpenRegistryCurrentUser(@"Software\nunit.org\VSAdapter"); UseVsKeepEngineRunning = registry.Exist("UseVsKeepEngineRunning") && (registry.Read<int>("UseVsKeepEngineRunning") == 1); ShadowCopy = registry.Exist("ShadowCopy") && (registry.Read<int>("ShadowCopy") == 1); #if DEBUG && VERBOSE Verbosity = 1; #else Verbosity = (registry.Exist("Verbosity")) ? registry.Read<int>("Verbosity") : 0; #endif } catch (Exception e) { messageLogger.SendMessage(TestMessageLevel.Error, "Unable to access registry. Default settings will be used"); messageLogger.SendMessage(TestMessageLevel.Error, e.ToString()); } TestEngine = new TestEngine(); TestLog = new TestLogger(messageLogger, Verbosity); }
public static int Main(string[] args) { AgentId = new Guid(args[0]); AgencyUrl = args[1]; InternalTraceLevel traceLevel = InternalTraceLevel.Off; for (int i = 2; i < args.Length; i++) { string arg = args[i]; // NOTE: we can test these strings exactly since // they originate from the engine itself. if (arg == "--debug-agent") { if (!Debugger.IsAttached) Debugger.Launch(); } else if (arg.StartsWith("--trace:")) { traceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), arg.Substring(8)); } } // Initialize trace so we can see what's happening int pid = Process.GetCurrentProcess().Id; string logname = string.Format(LOG_FILE_FORMAT, pid); InternalTrace.Initialize(logname, traceLevel); log.Info("Agent process {0} starting", pid); log.Info("Running under version {0}, {1}", Environment.Version, RuntimeFramework.CurrentFramework.DisplayName); // Create TestEngine - this program is // conceptually part of the engine and // can access it's internals as needed. TestEngine engine = new TestEngine(); // TODO: We need to get this from somewhere. Argument? engine.InternalTraceLevel = InternalTraceLevel.Debug; // Custom Service Initialization //log.Info("Adding Services"); engine.Services.Add(new SettingsService(false)); engine.Services.Add(new ExtensionService()); engine.Services.Add(new ProjectService()); engine.Services.Add(new DomainManager()); engine.Services.Add(new InProcessTestRunnerFactory()); engine.Services.Add(new DriverService()); //engine.Services.Add( new TestLoader() ); // Initialize Services log.Info("Initializing Services"); engine.Initialize(); Channel = ServerUtilities.GetTcpChannel(); log.Info("Connecting to TestAgency at {0}", AgencyUrl); try { Agency = Activator.GetObject(typeof(ITestAgency), AgencyUrl) as ITestAgency; } catch (Exception ex) { log.Error("Unable to connect", ex); } if (Channel != null) { log.Info("Starting RemoteTestAgent"); RemoteTestAgent agent = new RemoteTestAgent(AgentId, Agency, engine.Services); try { if (agent.Start()) { log.Debug("Waiting for stopSignal"); agent.WaitForStop(); log.Debug("Stop signal received"); } else log.Error("Failed to start RemoteTestAgent"); } catch (Exception ex) { log.Error("Exception in RemoteTestAgent", ex); } //log.Info("Unregistering Channel"); try { ChannelServices.UnregisterChannel(Channel); } catch (Exception ex) { log.Error("ChannelServices.UnregisterChannel threw an exception", ex); } } log.Info("Agent process {0} exiting", Process.GetCurrentProcess().Id); return 0; }
private void ExecuteNUnitTestRunner(IServer server, BuildInstructions instructions) { log.Log(LogSeverity.Information, "Executing NUnit Test Runner"); XmlNode result2; using (var r = new TestEngine()) { r.Initialize(); var pkg = new TestPackage(instructions.TargetUnitTestingAssembly); using (var runner = r.GetRunner(pkg)) { var filter = TestFilter.Empty; var tests = runner.CountTestCases(filter); log.Log(LogSeverity.Information, $"Found {tests} tests"); result2 = runner.Run(null, filter); } } Func<string, TestStatus> parse = x => { if(x == "Passed") return TestStatus.Passed; return TestStatus.Failed; }; ClientInformation status; try { var root = XDocument.Parse(result2.OuterXml); var testResults = from el in root.Descendants("test-case") select new TestResult(el.Attribute("name").Value, parse(el.Attribute("result").Value)); status = new ClientInformation(Environment.MachineName, instructions.Session, BuildStatus.Successful, testResults.ToArray()); } catch (Exception e) { var msg = "Error parsing test result XML document, check version of NUnit"; log.Log(LogSeverity.Error, msg); throw new ApplicationException(msg, e); } server.UpdateClientStatus(status); log.Log(LogSeverity.Information, "Test fixtures execution complete"); }