/// <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); // We display the filters at this point so that any exception message // thrown by CreateTestFilter will be understandable. _textUI.DisplayTestFilters(); TestFilter filter = CreateTestFilter(_options); if (_runner.Load(assembly, runSettings) != null) { return(_options.Explore ? ExploreTests() : RunTests(filter, runSettings)); } #else Assembly assembly = callingAssembly; if (_runner.Load(assembly, new Dictionary <string, object>()) != null) { return(RunTests(TestFilter.Empty, null)); } #endif var assemblyName = AssemblyHelper.GetAssemblyName(assembly); _textUI.DisplayError(string.Format("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); } }
// 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 . . ."); } } }
/// <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 }
/// <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 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 }