/// <summary> /// Execute a test run based on the aruments passed /// from Main. /// </summary> /// <param name="args">An array of arguments</param> public void Execute(string[] args) { // NOTE: Execute must be directly called from the // test assembly in order for the mechanism to work. this._commandLineOptions = new CommandLineOptions(); _commandLineOptions.Parse(args); if (_commandLineOptions.OutFile != null) this._writer = new StreamWriter(_commandLineOptions.OutFile); if (!_commandLineOptions.NoHeader) WriteHeader(this._writer); if (_commandLineOptions.ShowHelp) _writer.Write(_commandLineOptions.HelpText); else if (_commandLineOptions.Error) { _writer.WriteLine(_commandLineOptions.ErrorMessage); _writer.WriteLine(_commandLineOptions.HelpText); } else { Assembly callingAssembly = Assembly.GetCallingAssembly(); // We must call this before creating the runner so that any internal logging is initialized InitializeInternalTrace(callingAssembly.Location, _commandLineOptions.InternalTraceLevel); _runner = new NUnitLiteTestAssemblyRunner(new DefaultTestAssemblyBuilder()); WriteRuntimeEnvironment(this._writer); if (_commandLineOptions.Wait && _commandLineOptions.OutFile != null) _writer.WriteLine("Ignoring /wait option - only valid for Console"); // We only have one commandline option that has to be passed // to the runner, so we do it here for convenience. var runnerSettings = new Dictionary<string, object>(); if (_commandLineOptions.InitialSeed >= 0) runnerSettings[DriverSettings.RandomSeed] = _commandLineOptions.InitialSeed; TestFilter filter = _commandLineOptions.Tests.Count > 0 ? new SimpleNameFilter(_commandLineOptions.Tests) : TestFilter.Empty; try { foreach (string name in _commandLineOptions.Parameters) _assemblies.Add(Assembly.Load(name)); if (_assemblies.Count == 0) _assemblies.Add(callingAssembly); // TODO: For now, ignore all but first assembly Assembly assembly = _assemblies[0]; //Randomizer.InitialSeed = _commandLineOptions.InitialSeed; if (_runner.Load(assembly, runnerSettings) == null) { var assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return; } if (_commandLineOptions.Explore) ExploreTests(); else { if (_commandLineOptions.Include != null && _commandLineOptions.Include != string.Empty) { TestFilter includeFilter = new SimpleCategoryExpression(_commandLineOptions.Include).Filter; if (filter.IsEmpty) filter = includeFilter; else filter = new AndFilter(filter, includeFilter); } if (_commandLineOptions.Exclude != null && _commandLineOptions.Exclude != string.Empty) { TestFilter excludeFilter = new NotFilter(new SimpleCategoryExpression(_commandLineOptions.Exclude).Filter); if (filter.IsEmpty) filter = excludeFilter; else if (filter is AndFilter) ((AndFilter)filter).Add(excludeFilter); else filter = new AndFilter(filter, excludeFilter); } RunTests(filter); } } catch (FileNotFoundException ex) { _writer.WriteLine(ex.Message); } catch (Exception ex) { _writer.WriteLine(ex.ToString()); } finally { if (_commandLineOptions.OutFile == null) { if (_commandLineOptions.Wait) { Console.WriteLine("Press Enter key to continue . . ."); Console.ReadLine(); } } else { _writer.Close(); } } } }
/// <summary> /// Execute a test run based on the aruments passed /// from Main. /// </summary> /// <param name="args">An array of arguments</param> public void Execute(string[] args) { // NOTE: Execute must be directly called from the // test assembly in order for the mechanism to work. _options = new CommandLineOptions(args); _workDirectory = _options.WorkDirectory; if (_workDirectory == null) _workDirectory = Environment.CurrentDirectory; else if (!Directory.Exists(_workDirectory)) Directory.CreateDirectory(_workDirectory); #if !SILVERLIGHT if (_options.DisplayTeamCityServiceMessages) _teamCity = new TeamCityEventListener(); if (_options.OutFile != null) { _outWriter = new StreamWriter(Path.Combine(_workDirectory, _options.OutFile)); Console.SetOut(_outWriter); } if (_options.ErrFile != null) { _errWriter = new StreamWriter(Path.Combine(_workDirectory, _options.ErrFile)); Console.SetError(_errWriter); } #endif if (!_options.NoHeader) WriteHeader(_outWriter); if (_options.ShowHelp) _outWriter.Write(_options.HelpText); else if (_options.ErrorMessages.Count > 0) { foreach(string line in _options.ErrorMessages) _outWriter.WriteLine(line); _outWriter.WriteLine(_options.HelpText); } else { Assembly callingAssembly = Assembly.GetCallingAssembly(); // We must call this before creating the runner so that any internal logging is initialized InternalTraceLevel level = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), _options.InternalTraceLevel, true); InitializeInternalTrace(callingAssembly.Location, level); _runner = new NUnitLiteTestAssemblyRunner(new DefaultTestAssemblyBuilder()); DisplayRequestedOptions(_outWriter); WriteRuntimeEnvironment(_outWriter); if (_options.Wait && _options.OutFile != null) _outWriter.WriteLine("Ignoring /wait option - only valid for Console"); var runSettings = MakeRunSettings(_options); TestFilter filter = CreateTestFilter(_options); try { foreach (string name in _options.InputFiles) _assemblies.Add(Assembly.Load(name)); if (_assemblies.Count == 0) _assemblies.Add(callingAssembly); // TODO: For now, ignore all but first assembly Assembly assembly = _assemblies[0]; //Randomizer.InitialSeed = _commandLineOptions.InitialSeed; if (_runner.Load(assembly, runSettings) == null) { var assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return; } if (_options.Explore) ExploreTests(); else { RunTests(filter); } } catch (FileNotFoundException ex) { _outWriter.WriteLine(ex.Message); } catch (Exception ex) { _outWriter.WriteLine(ex.ToString()); } finally { if (_options.OutFile == null) { if (_options.Wait) { Console.WriteLine("Press Enter key to continue . . ."); Console.ReadLine(); } } else { _outWriter.Close(); } if (_options.ErrFile != null) _errWriter.Close(); } } }
private bool LoadTestAssembly() { return(runner.Load(callingAssembly, new Dictionary <string, string>()) != null); }
/// <summary> /// Loads the tests found in an Assembly, returning an indication of whether or not the load succeeded. /// </summary> /// <param name="runner">The test assembly runner to load the test assembly in to.</param> /// <param name="assembly">The assembly to load.</param> /// <param name="settings">Dictionary of options to use in loading the test.</param> /// <returns>A <see cref="Test" /> representing the loaded tests.</returns> protected virtual Test LoadTest(ITestAssemblyRunner runner, Assembly assembly, IDictionary <string, object> settings) { return(runner?.Load(assembly, settings) as Test); }
// Internal Execute depends on _textUI and _options having been set already. private int Execute() { _runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); InitializeInternalTrace(); try { if (!Directory.Exists(_options.WorkDirectory)) { Directory.CreateDirectory(_options.WorkDirectory); } if (_options.TeamCity) { _teamCity = new TeamCityEventListener(_textUI.Writer); } if (_options.ShowVersion || !_options.NoHeader) { _textUI.DisplayHeader(); } if (_options.ShowHelp) { _textUI.DisplayHelp(); return(TextRunner.OK); } // We already showed version as a part of the header if (_options.ShowVersion) { return(TextRunner.OK); } if (_options.ErrorMessages.Count > 0) { _textUI.DisplayErrors(_options.ErrorMessages); _textUI.Writer.WriteLine(); _textUI.DisplayHelp(); return(TextRunner.INVALID_ARG); } if (_testAssembly == null && _options.InputFile == null) { _textUI.DisplayError("No test assembly was specified."); _textUI.Writer.WriteLine(); _textUI.DisplayHelp(); return(TextRunner.OK); } _textUI.DisplayRuntimeEnvironment(); var testFile = _testAssembly != null ? AssemblyHelper.GetAssemblyPath(_testAssembly) : _options.InputFile; _textUI.DisplayTestFiles(new string[] { testFile }); if (_testAssembly == null) { _testAssembly = AssemblyHelper.Load(testFile); } if (_options.WaitBeforeExit && _options.OutFile != null) { _textUI.DisplayWarning("Ignoring /wait option - only valid for Console"); } var runSettings = MakeRunSettings(_options); // We display the filters at this point so that any exception message // thrown by CreateTestFilter will be understandable. _textUI.DisplayTestFilters(); TestFilter filter = CreateTestFilter(_options); _runner.Load(_testAssembly, runSettings); return(_options.Explore ? ExploreTests(filter) : RunTests(filter, runSettings)); } catch (FileNotFoundException ex) { _textUI.DisplayError(ex.Message); return(FILE_NOT_FOUND); } catch (Exception ex) { _textUI.DisplayError(ex.ToString()); return(UNEXPECTED_ERROR); } finally { if (_options.WaitBeforeExit) { _textUI.WaitForUser("Press Enter key to continue . . ."); } } }
public void Load_FileNotFound_ReturnsNonRunnableSuite() { var result = _runner.Load(MISSING_FILE, EMPTY_SETTINGS); Assert.That(result.IsSuite); Assert.That(result, Is.TypeOf <TestAssembly>()); Assert.That(result.Name, Is.EqualTo(MISSING_FILE)); Assert.That(result.RunState, Is.EqualTo(Interfaces.RunState.NotRunnable)); Assert.That(result.TestCaseCount, Is.EqualTo(0)); Assert.That(result.Properties.Get(PropertyNames.SkipReason), Does.StartWith(COULD_NOT_LOAD_MSG)); }
/// <summary> /// Execute a test run based on the aruments passed /// from Main. /// </summary> /// <param name="args">An array of arguments</param> public void Execute(string[] args) { // NOTE: Execute must be directly called from the // test assembly in order for the mechanism to work. Assembly callingAssembly = Assembly.GetCallingAssembly(); this.commandLineOptions = new CommandLineOptions(); commandLineOptions.Parse(args); if (commandLineOptions.OutFile != null) { this.writer = new StreamWriter(commandLineOptions.OutFile); } if (!commandLineOptions.NoHeader) { WriteHeader(this.writer); } if (commandLineOptions.ShowHelp) { writer.Write(commandLineOptions.HelpText); } else if (commandLineOptions.Error) { writer.WriteLine(commandLineOptions.ErrorMessage); writer.WriteLine(commandLineOptions.HelpText); } else { WriteRuntimeEnvironment(this.writer); if (commandLineOptions.Wait && commandLineOptions.OutFile != null) { writer.WriteLine("Ignoring /wait option - only valid for Console"); } // We only have one commandline option that has to be passed // to the runner, so we do it here for convenience. var runnerSettings = new Dictionary <string, object>(); if (commandLineOptions.InitialSeed >= 0) { runnerSettings[DriverSettings.RandomSeed] = commandLineOptions.InitialSeed; } TestFilter filter = commandLineOptions.Tests.Count > 0 ? new SimpleNameFilter(commandLineOptions.Tests) : TestFilter.Empty; try { foreach (string name in commandLineOptions.Parameters) { assemblies.Add(Assembly.Load(name)); } if (assemblies.Count == 0) { assemblies.Add(callingAssembly); } // TODO: For now, ignore all but first assembly Assembly assembly = assemblies[0]; //Randomizer.InitialSeed = commandLineOptions.InitialSeed; if (runner.Load(assembly, runnerSettings) == null) { var assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return; } if (commandLineOptions.Explore) { ExploreTests(); } else { if (commandLineOptions.Include != null && commandLineOptions.Include != string.Empty) { TestFilter includeFilter = new SimpleCategoryExpression(commandLineOptions.Include).Filter; if (filter.IsEmpty) { filter = includeFilter; } else { filter = new AndFilter(filter, includeFilter); } } if (commandLineOptions.Exclude != null && commandLineOptions.Exclude != string.Empty) { TestFilter excludeFilter = new NotFilter(new SimpleCategoryExpression(commandLineOptions.Exclude).Filter); if (filter.IsEmpty) { filter = excludeFilter; } else if (filter is AndFilter) { ((AndFilter)filter).Add(excludeFilter); } else { filter = new AndFilter(filter, excludeFilter); } } RunTests(filter); } } catch (FileNotFoundException ex) { writer.WriteLine(ex.Message); } catch (Exception ex) { writer.WriteLine(ex.ToString()); } finally { if (commandLineOptions.OutFile == null) { if (commandLineOptions.Wait) { Console.WriteLine("Press Enter key to continue . . ."); Console.ReadLine(); } } else { writer.Close(); } } } }
/// <summary> /// Execute a test run based on the aruments passed /// from Main. /// </summary> /// <param name="args">An array of arguments</param> public void Execute(string[] args) { // NOTE: Execute must be directly called from the // test assembly in order for the mechanism to work. Assembly callingAssembly = Assembly.GetCallingAssembly(); this.commandLineOptions = ProcessArguments(args); if (!commandLineOptions.ShowHelp && !commandLineOptions.Error) { if (commandLineOptions.Wait && commandLineOptions.OutFile != null) { writer.WriteLine("Ignoring /wait option - only valid for Console"); } IDictionary loadOptions = new Hashtable(); //if (options.Load.Count > 0) // loadOptions["LOAD"] = options.Load; IDictionary runOptions = new Hashtable(); if (commandLineOptions.TestCount > 0) { runOptions["RUN"] = commandLineOptions.Tests; } try { foreach (string name in commandLineOptions.Parameters) { assemblies.Add(Assembly.Load(name)); } if (assemblies.Count == 0) { assemblies.Add(callingAssembly); } // TODO: For now, ignore all but first assembly Assembly assembly = assemblies[0] as Assembly; if (!runner.Load(assembly, loadOptions)) { Console.WriteLine("No tests found in assembly {0}", assembly.GetName().Name); return; } if (commandLineOptions.Explore) { ExploreTests(); } else { RunTests(); } } catch (FileNotFoundException ex) { writer.WriteLine(ex.Message); } catch (Exception ex) { writer.WriteLine(ex.ToString()); } finally { if (commandLineOptions.OutFile == null) { if (commandLineOptions.Wait) { Console.WriteLine("Press Enter key to continue . . ."); Console.ReadLine(); } } else { writer.Close(); } } } }
public void LoadTest(string[] args) { //TLogger.Write("LoadTest .................."); _options = new NUnitLiteOptions(args); ExtendedTextWriter outWriter = null; outWriter = new ColorConsoleWriter(); _textUI = new TextUI(outWriter, Console.In, _options); _runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); try { #if !SILVERLIGHT && !PORTABLE if (!Directory.Exists(_options.WorkDirectory)) { Directory.CreateDirectory(_options.WorkDirectory); } #if !NETCF if (_options.TeamCity) { _teamCity = new TeamCityEventListener(); } #endif #endif if (_options.ShowVersion || !_options.NoHeader) { _textUI.DisplayHeader(); } if (_options.ShowHelp) { _textUI.DisplayHelp(); return; } // We already showed version as a part of the header if (_options.ShowVersion) { return; } if (_options.ErrorMessages.Count > 0) { _textUI.DisplayErrors(_options.ErrorMessages); _textUI.DisplayHelp(); return; } _textUI.DisplayRuntimeEnvironment(); var testFile = _testAssembly != null ? AssemblyHelper.GetAssemblyPath(_testAssembly) : _options.InputFiles.Count > 0 ? _options.InputFiles[0] : null; //TLogger.Write("Input File [0]:" + _options.InputFiles[0]); //TLogger.Write("Input File Format Size :"+ _options.InputFiles.Count); if (testFile != null) { _textUI.DisplayTestFiles(new string[] { testFile }); //TLogger.Write("after DisplayTestFiles"); if (_testAssembly == null) { _testAssembly = AssemblyHelper.Load(testFile); } } if (_options.WaitBeforeExit && _options.OutFile != null) { _textUI.DisplayWarning("Ignoring /wait option - only valid for Console"); } foreach (string nameOrPath in _options.InputFiles) { //TLogger.Write("In foreach" + nameOrPath); _assemblies.Add(AssemblyHelper.Load(nameOrPath)); } // We display the filters at this point so that any exception message // thrown by CreateTestFilter will be understandable. _textUI.DisplayTestFilters(); var runSettings = MakeRunSettings(_options); TestFilter filter = CreateTestFilter(_options); _runner.Load(_testAssembly, runSettings); } catch (FileNotFoundException ex) { _textUI.DisplayError(ex.Message); return; } catch (Exception ex) { _textUI.DisplayError(ex.ToString()); return; } #if !SILVERLIGHT finally { if (_options.WaitBeforeExit) { _textUI.WaitForUser("Press Enter key to continue . . ."); } if (_options.OutFile != null && outWriter != null) { outWriter.Flush(); } } #endif }
public void Load_FileNotFound_ReturnsNonRunnableSuite() { var result = _runner.Load(MISSING_FILE, EMPTY_SETTINGS); Assert.That(result.IsSuite); Assert.That(result, Is.TypeOf <TestAssembly>()); Assert.That(result.Name, Is.EqualTo(MISSING_FILE)); Assert.That(result.RunState, Is.EqualTo(Interfaces.RunState.NotRunnable)); Assert.That(result.TestCaseCount, Is.EqualTo(0)); Assert.That(result.Properties.Get(PropertyNames.SkipReason), Does.StartWith(REALLY_RUNNING_ON_CF ? "File or assembly name" : "Could not load")); }
/// <summary> /// Execute a test run based on the aruments passed /// from Main. /// </summary> /// <param name="args">An array of arguments</param> public void Execute(string[] args) { // NOTE: Execute must be directly called from the // test assembly in order for the mechanism to work. Assembly callingAssembly = Assembly.GetCallingAssembly(); this.commandLineOptions = new CommandLineOptions(); commandLineOptions.Parse(args); if (commandLineOptions.OutFile != null) { this.writer = new StreamWriter(commandLineOptions.OutFile); } if (!commandLineOptions.NoHeader) { WriteHeader(this.writer); } if (commandLineOptions.ShowHelp) { writer.Write(commandLineOptions.HelpText); } else if (commandLineOptions.Error) { writer.WriteLine(commandLineOptions.ErrorMessage); writer.WriteLine(commandLineOptions.HelpText); } else { WriteRuntimeEnvironment(this.writer); if (commandLineOptions.Wait && commandLineOptions.OutFile != null) { writer.WriteLine("Ignoring /wait option - only valid for Console"); } #if SILVERLIGHT IDictionary loadOptions = new System.Collections.Generic.Dictionary <string, string>(); #else IDictionary loadOptions = new Hashtable(); #endif //if (options.Load.Count > 0) // loadOptions["LOAD"] = options.Load; //IDictionary runOptions = new Hashtable(); //if (commandLineOptions.TestCount > 0) // runOptions["RUN"] = commandLineOptions.Tests; ITestFilter filter = commandLineOptions.TestCount > 0 ? new SimpleNameFilter(commandLineOptions.Tests) : TestFilter.Empty; try { foreach (string name in commandLineOptions.Parameters) { assemblies.Add(Assembly.Load(name)); } if (assemblies.Count == 0) { assemblies.Add(callingAssembly); } // TODO: For now, ignore all but first assembly Assembly assembly = assemblies[0] as Assembly; Randomizer.InitialSeed = commandLineOptions.InitialSeed; if (!runner.Load(assembly, loadOptions)) { AssemblyName assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return; } if (commandLineOptions.Explore) { ExploreTests(); } else { if (commandLineOptions.Include != null && commandLineOptions.Include != string.Empty) { TestFilter includeFilter = new SimpleCategoryExpression(commandLineOptions.Include).Filter; if (filter.IsEmpty) { filter = includeFilter; } else { filter = new AndFilter(filter, includeFilter); } } if (commandLineOptions.Exclude != null && commandLineOptions.Exclude != string.Empty) { TestFilter excludeFilter = new NotFilter(new SimpleCategoryExpression(commandLineOptions.Exclude).Filter); if (filter.IsEmpty) { filter = excludeFilter; } else if (filter is AndFilter) { ((AndFilter)filter).Add(excludeFilter); } else { filter = new AndFilter(filter, excludeFilter); } } RunTests(filter); } } catch (FileNotFoundException ex) { writer.WriteLine(ex.Message); } catch (Exception ex) { writer.WriteLine(ex.ToString()); } finally { if (commandLineOptions.OutFile == null) { if (commandLineOptions.Wait) { Console.WriteLine("Press Enter key to continue . . ."); Console.ReadLine(); } } else { writer.Close(); } } } }
/// <inheritdoc /> public ITest Load(string assemblyName, IDictionary <string, object> settings) { v_IsTestLoadedOverride = false; return(v_Runner.Load(assemblyName, settings)); }
/// <summary> /// Execute a test run based on the aruments passed /// from Main. /// </summary> /// <param name="args">An array of arguments</param> public int Execute(string[] args) { // NOTE: Execute must be directly called from the // test assembly in order for the mechanism to work. _options = new ConsoleOptions(args); _workDirectory = _options.WorkDirectory; if (_workDirectory == null) { _workDirectory = NUnit.Env.DefaultWorkDirectory; } else if (!Directory.Exists(_workDirectory)) { Directory.CreateDirectory(_workDirectory); } #if !SILVERLIGHT #if !NETCF if (_options.TeamCity) { _teamCity = new TeamCityEventListener(); } #endif if (_options.OutFile != null) { _outWriter = new ExtendedTextWriter(new StreamWriter(Path.Combine(_workDirectory, _options.OutFile))); Console.SetOut(_outWriter); ColorConsole.Enabled = false; } if (_options.ErrFile != null) { _errWriter = new StreamWriter(Path.Combine(_workDirectory, _options.ErrFile)); Console.SetError(_errWriter); } #endif if (_options.NoColor) { ColorConsole.Enabled = false; } if (!_options.NoHeader) { WriteHeader(_outWriter); } if (_options.ShowHelp) { WriteHelpText(); return(OK); } if (_options.ErrorMessages.Count > 0) { foreach (string line in _options.ErrorMessages) { _outWriter.WriteLine(line); } _options.WriteOptionDescriptions(_outWriter); return(INVALID_ARG); } Assembly callingAssembly = Assembly.GetCallingAssembly(); // We must call this before creating the runner so that any internal logging is initialized var level = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), _options.InternalTraceLevel ?? "Off", true); #if NETCF // NETCF: Try to unify InitializeInternalTrace(callingAssembly.GetName().CodeBase, level); #else InitializeInternalTrace(callingAssembly.Location, level); #endif _runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); _outWriter.WriteLine(ColorStyle.SectionHeader, "Test Files:"); DisplayRequestedOptions(_outWriter); WriteRuntimeEnvironment(_outWriter); if (_options.WaitBeforeExit && _options.OutFile != null) { _outWriter.WriteLine("Ignoring /wait option - only valid for Console"); } var runSettings = MakeRunSettings(_options); TestFilter filter = CreateTestFilter(_options); try { foreach (string name in _options.InputFiles) #if NETCF { _assemblies.Add(name.IndexOf(',') != -1 || (name.IndexOf('\\') == -1 && !Path.HasExtension(name)) ? Assembly.Load(name) : Assembly.LoadFrom(name)); } #else { _assemblies.Add(Assembly.Load(name)); } #endif if (_assemblies.Count == 0) { _assemblies.Add(callingAssembly); } // TODO: For now, ignore all but first assembly Assembly assembly = _assemblies[0]; // Randomizer.InitialSeed = _commandLineOptions.InitialSeed; if (_runner.Load(assembly, runSettings) != null) { return(_options.Explore ? ExploreTests() : RunTests(filter)); } var assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return(OK); } catch (FileNotFoundException ex) { _outWriter.WriteLine(ColorStyle.Error, ex.Message); return(FILE_NOT_FOUND); } catch (Exception ex) { _outWriter.WriteLine(ColorStyle.Error, ex.ToString()); return(UNEXPECTED_ERROR); } finally { if (_options.OutFile == null) { if (_options.WaitBeforeExit) { _outWriter.WriteLine(ColorStyle.Label, "Press Enter key to continue . . ."); Console.ReadLine(); } } else { _outWriter.Close(); } if (_options.ErrFile != null) { _errWriter.Close(); } } }
/// <summary> /// Execute a test run /// </summary> /// <param name="callingAssembly">The assembly from which tests are loaded</param> public int Execute(Assembly callingAssembly) { _runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); try { #if !SILVERLIGHT foreach (string nameOrPath in _options.InputFiles) _assemblies.Add(AssemblyHelper.Load(nameOrPath)); if (_assemblies.Count == 0) _assemblies.Add(callingAssembly); // TODO: For now, ignore all but first assembly Assembly assembly = _assemblies[0]; var runSettings = MakeRunSettings(_options); TestFilter filter = CreateTestFilter(_options); if (_runner.Load(assembly, runSettings) != null) return _options.Explore ? ExploreTests() : RunTests(filter); #else Assembly assembly = callingAssembly; if (_runner.Load(assembly, new Dictionary<string, object>()) != null) return RunTests(TestFilter.Empty); #endif var assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return OK; } catch (FileNotFoundException ex) { _textUI.DisplayError(ex.Message); return FILE_NOT_FOUND; } catch (Exception ex) { _textUI.DisplayError(ex.ToString()); return UNEXPECTED_ERROR; } }
/// <summary> /// Execute a test run based on the aruments passed /// from Main. /// </summary> /// <param name="args">An array of arguments</param> public void Execute(string[] args) { this.commandLineOptions = new CommandLineOptions(); commandLineOptions.Parse(args); if (runner == null) { #if MONODROID_TOOLS if (!string.IsNullOrEmpty(commandLineOptions.Android)) { runner = AndroidRunner(commandLineOptions.Android); } else if (!string.IsNullOrEmpty(commandLineOptions.Remote) && commandLineOptions.Remote.StartsWith("android:")) { Xamarin.AndroidRemoteRunner.App = commandLineOptions.Remote.Substring(8); runner = DefaultRunner(); } else #elif MONOTOUCH_TOOLS if (!string.IsNullOrEmpty(commandLineOptions.iOS)) { runner = iOSRunner(commandLineOptions.iOS); } else if (!string.IsNullOrEmpty(commandLineOptions.Remote) && commandLineOptions.Remote.StartsWith("ios:")) { // Xamarin.iOSRemoteRunner.App = commandLineOptions.Remote.Substring (4); // runner = DefaultRunner (); throw new NotImplementedException(); } else #elif WASM_TOOLS if (!string.IsNullOrEmpty(commandLineOptions.WebAssembly)) { runner = WebAssemblyRunner(commandLineOptions.WebAssembly); } else if (!string.IsNullOrEmpty(commandLineOptions.Remote) && commandLineOptions.Remote.StartsWith("wasm:")) { // Xamarin.WebAssemblyRemoteRunner.App = commandLineOptions.Remote.Substring (5); // runner = DefaultRunner (); throw new NotImplementedException(); } else #endif { runner = DefaultRunner(); } } if (commandLineOptions.OutFile != null) { this.writer = new StreamWriter(commandLineOptions.OutFile); } if (!commandLineOptions.NoHeader) { WriteHeader(this.writer); } if (commandLineOptions.ShowHelp) { writer.Write(commandLineOptions.HelpText); } else if (commandLineOptions.Error) { writer.WriteLine(commandLineOptions.ErrorMessage); writer.WriteLine(commandLineOptions.HelpText); } else { WriteRuntimeEnvironment(this.writer); if (commandLineOptions.Wait && commandLineOptions.OutFile != null) { writer.WriteLine("Ignoring /wait option - only valid for Console"); } #if SILVERLIGHT IDictionary loadOptions = new System.Collections.Generic.Dictionary <string, string>(); #else IDictionary loadOptions = new Hashtable(); #endif //if (options.Load.Count > 0) // loadOptions["LOAD"] = options.Load; //IDictionary runOptions = new Hashtable(); //if (commandLineOptions.TestCount > 0) // runOptions["RUN"] = commandLineOptions.Tests; ITestFilter filter = commandLineOptions.TestCount > 0 ? new SimpleNameFilter(commandLineOptions.Tests) : TestFilter.Empty; try { foreach (string name in commandLineOptions.Parameters) { try { assemblies.Add(Assembly.LoadFrom(name)); } catch (FileNotFoundException /* e*/) { assemblies.Add(Assembly.Load(name)); } } if (assemblies.Count == 0) { // NOTE: Execute must be directly called from the // test assembly in order for the mechanism to work. Assembly callingAssembly = Assembly.GetCallingAssembly(); assemblies.Add(callingAssembly); } // TODO: For now, ignore all but first assembly Assembly assembly = assemblies[0] as Assembly; Randomizer.InitialSeed = commandLineOptions.InitialSeed; if (!runner.Load(assembly, loadOptions)) { AssemblyName assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return; } if (commandLineOptions.Explore) { ExploreTests(); } else { if (commandLineOptions.Include != null && commandLineOptions.Include != string.Empty) { TestFilter includeFilter = new SimpleCategoryExpression(commandLineOptions.Include).Filter; if (filter.IsEmpty) { filter = includeFilter; } else { filter = new AndFilter(filter, includeFilter); } } if (commandLineOptions.Exclude != null && commandLineOptions.Exclude != string.Empty) { TestFilter excludeFilter = new NotFilter(new SimpleCategoryExpression(commandLineOptions.Exclude).Filter); if (filter.IsEmpty) { filter = excludeFilter; } else if (filter is AndFilter) { ((AndFilter)filter).Add(excludeFilter); } else { filter = new AndFilter(filter, excludeFilter); } } #if (MONO && !MONO_NO_NUNIT24) filter = Xamarin.BabysitterSupport.AddBabysitterFilter(filter); #endif RunTests(filter); } } catch (FileNotFoundException ex) { Failure = true; writer.WriteLine(ex.Message); } catch (Exception ex) { Failure = true; writer.WriteLine(ex.ToString()); } finally { if (commandLineOptions.OutFile == null) { if (commandLineOptions.Wait) { Console.WriteLine("Press Enter key to continue . . ."); Console.ReadLine(); } } else { writer.Close(); } } } }
/// <summary> /// Execute a test run /// </summary> /// <param name="callingAssembly">The assembly from which tests are loaded</param> public int Execute(TextUI textUI, NUnitLiteOptions options) { _textUI = textUI; _options = options; _runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); try { #if !SILVERLIGHT && !PORTABLE if (!Directory.Exists(_options.WorkDirectory)) Directory.CreateDirectory(_options.WorkDirectory); #if !NETCF if (_options.TeamCity) _teamCity = new TeamCityEventListener(); #endif #endif if (_options.ShowVersion || !_options.NoHeader) _textUI.DisplayHeader(); if (_options.ShowHelp) { _textUI.DisplayHelp(); return TextRunner.OK; } // We already showed version as a part of the header if (_options.ShowVersion) return TextRunner.OK; if (_options.ErrorMessages.Count > 0) { _textUI.DisplayErrors(_options.ErrorMessages); _textUI.DisplayHelp(); return TextRunner.INVALID_ARG; } _textUI.DisplayRuntimeEnvironment(); var testFile = _testAssembly != null ? AssemblyHelper.GetAssemblyPath(_testAssembly) : _options.InputFiles.Count > 0 ? _options.InputFiles[0] : null; if (testFile != null) { _textUI.DisplayTestFiles(new string[] { testFile }); if (_testAssembly == null) _testAssembly = AssemblyHelper.Load(testFile); } if (_options.WaitBeforeExit && _options.OutFile != null) _textUI.DisplayWarning("Ignoring /wait option - only valid for Console"); foreach (string nameOrPath in _options.InputFiles) _assemblies.Add(AssemblyHelper.Load(nameOrPath)); var runSettings = MakeRunSettings(_options); // We display the filters at this point so that any exception message // thrown by CreateTestFilter will be understandable. _textUI.DisplayTestFilters(); TestFilter filter = CreateTestFilter(_options); _runner.Load(_testAssembly, runSettings); return _options.Explore ? ExploreTests() : RunTests(filter, runSettings); } catch (FileNotFoundException ex) { _textUI.DisplayError(ex.Message); return FILE_NOT_FOUND; } catch (Exception ex) { _textUI.DisplayError(ex.ToString()); return UNEXPECTED_ERROR; } #if !SILVERLIGHT finally { if (_options.WaitBeforeExit) _textUI.WaitForUser("Press Enter key to continue . . ."); } #endif }
public void Load_GoodFile_ReturnsRunnableSuite() { var result = _runner.Load(_mockAssemblyPath, _settings); Assert.That(result.IsSuite); Assert.That(result, Is.TypeOf <TestAssembly>()); Assert.That(result.Name, Is.EqualTo(MOCK_ASSEMBLY)); Assert.That(result.RunState, Is.EqualTo(Interfaces.RunState.Runnable)); Assert.That(result.TestCaseCount, Is.EqualTo(MockAssembly.Tests)); }