public Runner(ITestEngine engine, HostedOptions options) { _engine = engine; _options = options; _resultService = _engine.Services.GetService<IResultService>(); _filterService = _engine.Services.GetService<ITestFilterService>(); }
public void InitializeTestEngineResult() { // Save the local directory - used by GetLocalPath Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase); localDirectory = Path.GetDirectoryName(uri.LocalPath); AssemblyPath = GetLocalPath(AssemblyName); // Create a fresh copy of the engine, since we can't use the // one that is running this test. engine = TestEngineActivator.CreateInstance(); engine.InternalTraceLevel = InternalTraceLevel.Off; // Create a new DefaultAssemblyRunner, which is actually a framework class, // because we can't use the one that's currently running this test. var runner = new Runner(new Builder()); var settings = new Dictionary<string, object>(); // Make sure the runner loaded the mock assembly. Assert.That( runner.Load(AssemblyPath, settings).RunState.ToString(), Is.EqualTo("Runnable"), "Unable to load mock-nunit-assembly.exe"); // Run the tests, saving the result as an XML string var xmlText = runner.Run(TestListener.NULL, TestFilter.Empty).ToXml(true).OuterXml; // Create a TestEngineResult from the string, just as the TestEngine does, // then add a test-run element to the result, wrapping the result so it // looks just like what the engine would return! this.EngineResult = new TestEngineResult(xmlText).Aggregate("test-run", AssemblyName, AssemblyPath); }
public TestExplorerViewModel(VBE vbe, ITestEngine testEngine, TestExplorerModelBase model, IClipboardWriter clipboard) { _testEngine = testEngine; _testEngine.TestCompleted += TestEngineTestCompleted; _model = model; _clipboard = clipboard; _navigateCommand = new NavigateCommand(); _runAllTestsCommand = new RunAllTestsCommand(testEngine, model); _addTestModuleCommand = new AddTestModuleCommand(vbe); _addTestMethodCommand = new AddTestMethodCommand(vbe, model); _addErrorTestMethodCommand = new AddTestMethodExpectedErrorCommand(vbe, model); _refreshCommand = new DelegateCommand(ExecuteRefreshCommand, CanExecuteRefreshCommand); _repeatLastRunCommand = new DelegateCommand(ExecuteRepeatLastRunCommand, CanExecuteRepeatLastRunCommand); _runNotExecutedTestsCommand = new DelegateCommand(ExecuteRunNotExecutedTestsCommand, CanExecuteRunNotExecutedTestsCommand); _runFailedTestsCommand = new DelegateCommand(ExecuteRunFailedTestsCommand, CanExecuteRunFailedTestsCommand); _runPassedTestsCommand = new DelegateCommand(ExecuteRunPassedTestsCommand, CanExecuteRunPassedTestsCommand); _runSelectedTestCommand = new DelegateCommand(ExecuteSelectedTestCommand, CanExecuteSelectedTestCommand); _copyResultsCommand = new DelegateCommand(ExecuteCopyResultsCommand); }
public ConsoleRunner(ITestEngine engine, ConsoleOptions options) { _engine = engine; _options = options; _workDirectory = options.WorkDirectory; if (_workDirectory == null) _workDirectory = Environment.CurrentDirectory; else if (!Directory.Exists(_workDirectory)) Directory.CreateDirectory(_workDirectory); }
public ConsoleRunner(ITestEngine engine, ConsoleOptions options, ExtendedTextWriter writer) { _engine = engine; _options = options; _outWriter = writer; _workDirectory = options.WorkDirectory; if (_workDirectory == null) _workDirectory = Environment.CurrentDirectory; else if (!Directory.Exists(_workDirectory)) Directory.CreateDirectory(_workDirectory); _resultService = _engine.Services.GetService<IResultService>(); }
public TestExplorerDockablePresenter(VBE vbe, AddIn addin, ITestExplorerWindow control, ITestEngine testEngine, GridViewSort<TestExplorerItem> gridViewSort) : base(vbe, addin, control) { _testEngine = testEngine; _gridViewSort = gridViewSort; _testEngine.ModuleInitialize += _testEngine_ModuleInitialize; _testEngine.ModuleCleanup += _testEngine_ModuleCleanup; _testEngine.MethodInitialize += TestEngineMethodInitialize; _testEngine.MethodCleanup += TestEngineMethodCleanup; _view = control; _view.SortColumn += SortColumn; RegisterTestExplorerEvents(); }
public ConsoleRunner(ITestEngine engine, ConsoleOptions options, ExtendedTextWriter writer) { _engine = engine; _options = options; _outWriter = writer; _workDirectory = options.WorkDirectory; if (_workDirectory == null) _workDirectory = Environment.CurrentDirectory; else if (!Directory.Exists(_workDirectory)) Directory.CreateDirectory(_workDirectory); _resultService = _engine.Services.GetService<IResultService>(); _filterService = _engine.Services.GetService<ITestFilterService>(); _extensionService = _engine.Services.GetService<IExtensionService>(); // Enable TeamCityEventListener immediately, before the console is redirected _extensionService.EnableExtension("NUnit.Engine.Listeners.TeamCityEventListener", _options.TeamCity); }
/// <summary> /// Runs the test in given assembly against the provided source assembly. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="TestResult"/>. /// </returns> public TestResult RunTests(TestRunRequest request) { Uri uri = new Uri(request.TestAssembly.CodeBase); this.localDirectory = Path.GetDirectoryName(uri.LocalPath); this.engine = TestEngineActivator.CreateInstance(null, InternalTraceLevel.Off); var settings = new Dictionary<string, object>(); var runner = new DefaultTestAssemblyRunner(new DefaultTestAssemblyBuilder()); runner.Load(request.TestAssembly, settings); // Convert our own framework XmlNode to a TestEngineResult var package = new TestPackage(this.GetLocalPath(uri.AbsolutePath)); this.engineResult = TestEngineResult.MakeTestRunResult( package, DateTime.Now, new TestEngineResult( runner.Run(TestListener.NULL, NUnit.Framework.Internal.TestFilter.Empty).ToXml(true).OuterXml)); return this.SummaryTransformTest(); }
public TestExplorerDockablePresenter(VBE vbe, AddIn addin, IDockableUserControl control, ITestEngine testEngine) : base(vbe, addin, control) { _testEngine = testEngine; _testEngine.ModuleInitialize += _testEngine_ModuleInitialize; _testEngine.ModuleCleanup += _testEngine_ModuleCleanup; _testEngine.MethodInitialize += TestEngineMethodInitialize; _testEngine.MethodCleanup += TestEngineMethodCleanup; RegisterTestExplorerEvents(); }
public void Init() { this.mockProcessHelper.Setup(o => o.GetCurrentProcessFileName()).Returns("vstest.console"); this.testEngine = new TestableTestEngine(this.mockProcessHelper.Object); }
public static int Main(string[] args) { Console.CancelKeyPress += new ConsoleCancelEventHandler(CancelHandler); try { Options.Parse(Options.PreParse(args)); } catch (OptionException ex) { WriteHeader(); OutWriter.WriteLine(ColorStyle.Error, string.Format(ex.Message, ex.OptionName)); return(ConsoleRunner.INVALID_ARG); } if (!string.IsNullOrEmpty(Options.ConsoleEncoding)) { try { Console.OutputEncoding = Encoding.GetEncoding(Options.ConsoleEncoding); } catch (Exception error) { WriteHeader(); OutWriter.WriteLine(ColorStyle.Error, string.Format("Unsupported Encoding, {0}", error.Message)); return(ConsoleRunner.INVALID_ARG); } } try { if (Options.ShowVersion || !Options.NoHeader) { WriteHeader(); } if (Options.ShowHelp || args.Length == 0) { WriteHelpText(); return(ConsoleRunner.OK); } // We already showed version as a part of the header if (Options.ShowVersion) { return(ConsoleRunner.OK); } if (Options.WarningMessages.Count != 0) { foreach (string message in Options.WarningMessages) { OutWriter.WriteLine(ColorStyle.Warning, message); } OutWriter.WriteLine(); } if (!Options.Validate()) { using (new ColorConsole(ColorStyle.Error)) { foreach (string message in Options.ErrorMessages) { Console.Error.WriteLine(message); } } return(ConsoleRunner.INVALID_ARG); } using (ITestEngine engine = TestEngineActivator.CreateInstance()) { if (Options.WorkDirectory != null) { engine.WorkDirectory = Options.WorkDirectory; } if (Options.InternalTraceLevel != null) { engine.InternalTraceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), Options.InternalTraceLevel); } try { return(new ConsoleRunner(engine, Options, OutWriter).Execute()); } catch (TestSelectionParserException ex) { OutWriter.WriteLine(ColorStyle.Error, ex.Message); return(ConsoleRunner.INVALID_ARG); } catch (FileNotFoundException ex) { OutWriter.WriteLine(ColorStyle.Error, ex.Message); return(ConsoleRunner.INVALID_ASSEMBLY); } catch (DirectoryNotFoundException ex) { OutWriter.WriteLine(ColorStyle.Error, ex.Message); return(ConsoleRunner.INVALID_ASSEMBLY); } catch (Exception ex) { OutWriter.WriteLine(ColorStyle.Error, ExceptionHelper.BuildMessage(ex)); OutWriter.WriteLine(); OutWriter.WriteLine(ColorStyle.Error, ExceptionHelper.BuildMessageAndStackTrace(ex)); return(ConsoleRunner.UNEXPECTED_ERROR); } finally { if (Options.WaitBeforeExit) { using (new ColorConsole(ColorStyle.Warning)) { Console.Out.WriteLine("\nPress any key to continue . . ."); Console.ReadKey(true); } } } } } finally { Console.ResetColor(); } }
public RunFailedTestsCommand(ITestEngine testEngine) { this.testEngine = testEngine; AddToCanExecuteEvaluation(SpecialEvaluateCanExecute); }
public static int Main(string[] args) { ConsoleOptions options = new ConsoleOptions(); try { options.Parse(args); } catch (OptionException ex) { WriteHeader(); Console.WriteLine(ex.Message, ex.OptionName); return(ConsoleRunner.INVALID_ARG); } ColorConsole.Options = options; // Create SettingsService early so we know the trace level right at the start //SettingsService settingsService = new SettingsService(); //InternalTraceLevel level = (InternalTraceLevel)settingsService.GetSetting("Options.InternalTraceLevel", InternalTraceLevel.Default); //if (options.trace != InternalTraceLevel.Default) // level = options.trace; //InternalTrace.Initialize("nunit-console_%p.log", level); //log.Info("NUnit-console.exe starting"); try { if (options.PauseBeforeRun) { ColorConsole.WriteLine(ColorStyle.Warning, "Press any key to continue . . ."); Console.ReadKey(true); } if (!options.NoHeader) { WriteHeader(); } if (options.ShowHelp) { WriteHelpText(options); return(ConsoleRunner.OK); } if (!options.Validate()) { using (new ColorConsole(ColorStyle.Error)) { foreach (string message in options.ErrorMessages) { Console.Error.WriteLine(message); } } return(ConsoleRunner.INVALID_ARG); } if (options.InputFiles.Count == 0) { using (new ColorConsole(ColorStyle.Error)) Console.Error.WriteLine("Error: no inputs specified"); return(ConsoleRunner.OK); } // TODO: Move this to engine foreach (string file in options.InputFiles) { //if (!Services.ProjectService.CanLoadProject(file) && !PathUtils.IsAssemblyFileType(file)) string ext = Path.GetExtension(file); if (ext != ".dll" && ext != ".exe" && ext != ".nunit") { ColorConsole.WriteLine(ColorStyle.Warning, "File type not known: " + file); return(ConsoleRunner.INVALID_ARG); } } string workDirectory = options.WorkDirectory ?? Environment.CurrentDirectory; var traceLevel = options.InternalTraceLevel != null ? (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), options.InternalTraceLevel) : InternalTraceLevel.Off; using (ITestEngine engine = TestEngineActivator.CreateInstance(workDirectory, traceLevel)) { try { return(new ConsoleRunner(engine, options).Execute()); } catch (NUnitEngineException ex) { ColorConsole.WriteLine(ColorStyle.Error, ex.Message); return(ConsoleRunner.INVALID_ARG); } catch (FileNotFoundException ex) { ColorConsole.WriteLine(ColorStyle.Error, ex.Message); #if DEBUG ColorConsole.WriteLine(ColorStyle.Error, ex.StackTrace); #endif return(ConsoleRunner.FILE_NOT_FOUND); } catch (DirectoryNotFoundException ex) { ColorConsole.WriteLine(ColorStyle.Error, ex.Message); return(ConsoleRunner.FILE_NOT_FOUND); } catch (Exception ex) { ColorConsole.WriteLine(ColorStyle.Error, ex.Message); return(ConsoleRunner.UNEXPECTED_ERROR); } finally { if (options.WaitBeforeExit) { using (new ColorConsole(ColorStyle.Warning)) { Console.Out.WriteLine("\nPress any key to continue . . ."); Console.ReadKey(true); } } // log.Info( "NUnit-console.exe terminating" ); } } } finally { Console.ResetColor(); } }
/// <summary> /// Loads the assembly that contains tests and run the tests. /// </summary> /// <param name="testAssembly"> /// Assembly that will be containing tests /// </param> private void LoadTestAndRunningAssembly(Assembly testAssembly) { Uri uri = new Uri(testAssembly.CodeBase); this.localDirectory = Path.GetDirectoryName(uri.LocalPath); this.engine = TestEngineActivator.CreateInstance(null, InternalTraceLevel.Off); var settings = new Dictionary<string, object>(); var runner = new DefaultTestAssemblyRunner(new DefaultTestAssemblyBuilder()); Assert.True(runner.Load(testAssembly, settings), "Unable to load Executing Assembly."); // Convert our own framework XmlNode to a TestEngineResult var package = new TestPackage(this.GetLocalPath(uri.AbsolutePath)); this.engineResult = TestEngineResult.MakeTestRunResult( package, DateTime.Now, new TestEngineResult( runner.Run(TestListener.NULL, NUnit.Framework.Internal.TestFilter.Empty).ToXml(true).OuterXml)); }
/// <summary> /// Initializes a new instance of the <see cref="TestPlatform"/> class. /// </summary> /// <param name="testEngine"> /// The test engine. /// </param> /// <param name="filehelper"> /// The filehelper. /// </param> /// <param name="testHostProviderManager"> /// The data. /// </param> protected TestPlatform(ITestEngine testEngine, IFileHelper filehelper, TestRuntimeProviderManager testHostProviderManager) { this.TestEngine = testEngine; this.fileHelper = filehelper; this.testHostProviderManager = testHostProviderManager; }
public static IUIElement EnterText(this ITestEngine engine, string automationId, string text) => engine.EnterText(automationId, text, null);
public TestableTestPlatform(ITestEngine testEngine, IFileHelper fileHelper, ITestRuntimeProvider hostProvider) : base(testEngine, fileHelper, new TestableTestRuntimeProviderManager(hostProvider)) { }
public TestableTestPlatform(ITestEngine testEngine, IFileHelper fileHelper) : base(testEngine, fileHelper) { }
public TestableTestPlatform(ITestEngine testEngine) : base(testEngine, new FileHelper()) { }
public TestModel(ITestEngine testEngine, CommandLineOptions options) { _testEngine = testEngine; Options = options; RecentFiles = GetService <IRecentFiles>(); }
public TestModel(ITestEngine testEngine) { _testEngine = testEngine; RecentFiles = testEngine.Services.GetService <IRecentFiles>(); Settings = new Settings.SettingsModel(testEngine.Services.GetService <ISettings>()); }
public void Initialize() { engine = TestEngineActivator.CreateInstance(); filterService = engine.Services.GetService <ITestFilterService>(); AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; }
public void CreateEngine() { _testEngine = new TestEngine(); _testEngine.InternalTraceLevel = InternalTraceLevel.Off; }
public TestExplorerDockablePresenter(VBE vbe, AddIn addin, ITestExplorerWindow control, ITestEngine testEngine, GridViewSort <TestExplorerItem> gridViewSort) : base(vbe, addin, control) { _testEngine = testEngine; _gridViewSort = gridViewSort; _testEngine.ModuleInitialize += _testEngine_ModuleInitialize; _testEngine.ModuleCleanup += _testEngine_ModuleCleanup; _testEngine.MethodInitialize += TestEngineMethodInitialize; _testEngine.MethodCleanup += TestEngineMethodCleanup; _view = control; _view.SortColumn += SortColumn; RegisterTestExplorerEvents(); }
public static void WaitForNoElementWithText(this ITestEngine engine, string text) => engine.WaitForNoElementWithText(text, null);
public static int Main(string[] args) { var options = new CommandLineOptions(args); if (options.ShowHelp) { // TODO: We would need to have a custom message box // in order to use a fixed font and display the options // so that the values all line up. MessageDisplay.Info(GetHelpText(options)); return(0); } if (!options.Validate()) { var NL = Environment.NewLine; var sb = new StringBuilder($"Error(s) in command line:{NL}"); foreach (string msg in options.ErrorMessages) { sb.Append($" {msg}{NL}"); } sb.Append($"{NL}{GetHelpText(options)}"); MessageDisplay.Error(sb.ToString()); return(2); } // Currently the InternalTraceLevel can only be set from the command-line. // We can't use user settings to provide a default because the settings // are an engine service and the engine have the internal trace level // set as part of its initialization. var traceLevel = options.InternalTraceLevel != null ? (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), options.InternalTraceLevel) : InternalTraceLevel.Off; // This initializes the trace setting for the GUI itself. InternalTrace.Initialize($"InternalTrace.{Process.GetCurrentProcess().Id}.gui.log", traceLevel); log.Info($"Starting TestCentric Runner - InternalTraceLevel = {traceLevel}"); log.Info("Creating TestEngine"); ITestEngine testEngine = TestEngineActivator.CreateInstance(); testEngine.InternalTraceLevel = traceLevel; log.Info("Instantiating TestModel"); ITestModel model = new TestModel(testEngine); model.PackageSettings.Add(EnginePackageSettings.InternalTraceLevel, traceLevel.ToString()); if (options.ProcessModel != null) { model.PackageSettings.Add(EnginePackageSettings.ProcessModel, options.ProcessModel); } if (options.DomainUsage != null) { model.PackageSettings.Add(EnginePackageSettings.DomainUsage, options.DomainUsage); } if (options.MaxAgents >= 0) { model.PackageSettings.Add(EnginePackageSettings.MaxAgents, options.MaxAgents); } if (options.RunAsX86) { model.PackageSettings.Add(EnginePackageSettings.RunAsX86, true); } log.Info("Constructing Form"); TestCentricMainView view = new TestCentricMainView(); log.Info("Constructing presenters"); new ProgressBarPresenter(view.ProgressBarView, model); new StatusBarPresenter(view.StatusBarView, model); new ErrorsAndFailuresPresenter(view.ErrorsAndFailuresView, model); new TestsNotRunPresenter(view.TestsNotRunView, model); new TextOutputPresenter(view.TextOutputView, model); new TreeViewPresenter(view.TreeView, model); new CategoryPresenter(view.CategoryView, model); new TestCentricPresenter(view, model, options); try { log.Info("Starting Gui Application"); Application.Run(view); log.Info("Application Exit"); } catch (Exception ex) { log.Error("Gui Application threw an exception", ex); throw; } finally { log.Info("Exiting TestCentric Runner"); InternalTrace.Close(); testEngine.Dispose(); } return(0); }
public static IUIElement WaitForElement(this ITestEngine engine, string automationId) => engine.WaitForElement(automationId, null);
public void Initialize () { engine = TestEngineActivator.CreateInstance (); filterService = engine.Services.GetService<ITestFilterService>(); }
public RunAllTestsCommand(ITestEngine engine, TestExplorerModelBase model) { _engine = engine; _model = model; }
public RunAllTestsCommand(ITestEngine engine) : base(LogManager.GetCurrentClassLogger()) { _engine = engine; }
public RepeatLastRunCommand(ITestEngine testEngine) : base(LogManager.GetCurrentClassLogger()) { this.testEngine = testEngine; }
public ConsoleTestRunner(ITestEngine engine, TestRunnerOptions options) : this(engine, options, new ExtendedTextWriter(), new FileSystem()) { }
public static int Main(string[] args) { try { Options.Parse(args); } catch (OptionException ex) { WriteHeader(); OutWriter.WriteLine(ColorStyle.Error, string.Format(ex.Message, ex.OptionName)); return(ConsoleRunner.INVALID_ARG); } //ColorConsole.Enabled = !Options.NoColor; // Create SettingsService early so we know the trace level right at the start //SettingsService settingsService = new SettingsService(); //InternalTraceLevel level = (InternalTraceLevel)settingsService.GetSetting("Options.InternalTraceLevel", InternalTraceLevel.Default); //if (options.trace != InternalTraceLevel.Default) // level = options.trace; //InternalTrace.Initialize("nunit-console_%p.log", level); //log.Info("NUnit-console.exe starting"); try { if (Options.PauseBeforeRun) { OutWriter.WriteLine(ColorStyle.Warning, "Press any key to continue . . ."); Console.ReadKey(true); } if (!Options.NoHeader) { WriteHeader(); } if (Options.ShowHelp) { WriteHelpText(); return(ConsoleRunner.OK); } if (!Options.Validate()) { using (new ColorConsole(ColorStyle.Error)) { foreach (string message in Options.ErrorMessages) { Console.Error.WriteLine(message); } } return(ConsoleRunner.INVALID_ARG); } if (Options.InputFiles.Count == 0) { using (new ColorConsole(ColorStyle.Error)) Console.Error.WriteLine("Error: no inputs specified"); return(ConsoleRunner.OK); } using (ITestEngine engine = TestEngineActivator.CreateInstance()) { if (Options.WorkDirectory != null) { engine.WorkDirectory = Options.WorkDirectory; } if (Options.InternalTraceLevel != null) { engine.InternalTraceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), Options.InternalTraceLevel); } try { return(new ConsoleRunner(engine, Options, OutWriter).Execute()); } catch (NUnitEngineException ex) { OutWriter.WriteLine(ColorStyle.Error, ex.Message); return(ConsoleRunner.INVALID_ARG); } catch (FileNotFoundException ex) { OutWriter.WriteLine(ColorStyle.Error, ex.Message); return(ConsoleRunner.FILE_NOT_FOUND); } catch (DirectoryNotFoundException ex) { OutWriter.WriteLine(ColorStyle.Error, ex.Message); return(ConsoleRunner.FILE_NOT_FOUND); } catch (Exception ex) { OutWriter.WriteLine(ColorStyle.Error, ex.ToString()); return(ConsoleRunner.UNEXPECTED_ERROR); } finally { if (Options.WaitBeforeExit) { using (new ColorConsole(ColorStyle.Warning)) { Console.Out.WriteLine("\nPress any key to continue . . ."); Console.ReadKey(true); } } // log.Info( "NUnit-console.exe terminating" ); } } } finally { Console.ResetColor(); } }
public ScenarioRunner(IBootstrapSpecify configuration, ITestEngine testEngine) { Configuration = configuration; _testEngine = testEngine; }
public static void Tap(this ITestEngine engine, string automationId) => engine.Tap(automationId, null);
public static void WaitForNoElement(this ITestEngine engine, string automationId) => engine.WaitForNoElement(automationId, null);
public virtual void StartApp() { AppManager.StartApp(); Engine = AppManager.Engine; }
public static void AssertTextInElementByAutomationId(this ITestEngine engine, string automationId, string text) => engine.AssertTextInElementByAutomationId(automationId, text, null);
public static bool ElementExists(this ITestEngine engine, string automationId) => engine.ElementExists(automationId, null);
public static void Screenshot(this ITestEngine engine, [CallerMemberName] string methodName = null) => engine.Screenshot(string.Empty, methodName);
public ScenarioRunner(IConfigureSpecify configuration, ITestEngine testEngine) { Configuration = configuration; _testEngine = testEngine; }
/// <summary> /// Initializes a new instance of the <see cref="TestPlatform"/> class. /// </summary> /// <param name="testEngine"> /// The test engine. /// </param> protected TestPlatform(ITestEngine testEngine, IFileHelper filehelper) { this.TestEngine = testEngine; this.fileHelper = filehelper; }