/// <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 the tests in the assembly, passing in /// a list of arguments. /// </summary> /// <param name="args">Execution options</param> public int Execute(string[] args) { var options = new ConsoleOptions(args); var callingAssembly = Assembly.GetCallingAssembly(); 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 ExtendedTextWriter outWriter = null; if (options.OutFile != null) { outWriter = new ExtendedTextWrapper(new StreamWriter(Path.Combine(options.WorkDirectory, options.OutFile))); Console.SetOut(outWriter); } TextWriter errWriter = null; if (options.ErrFile != null) { errWriter = new StreamWriter(Path.Combine(options.WorkDirectory, options.ErrFile)); Console.SetError(errWriter); } var _textUI = new TextUI(outWriter, options); if (!options.NoHeader) { _textUI.DisplayHeader(); } if (options.ShowHelp) { _textUI.DisplayHelp(); return(TextRunner.OK); } if (options.ErrorMessages.Count > 0) { _textUI.DisplayErrors(options.ErrorMessages); _textUI.DisplayHelp(); return(TextRunner.INVALID_ARG); } if (options.InputFiles.Count > 0) { _textUI.DisplayError("Input assemblies may not be specified when using the NUnitLite AutoRunner"); return(TextRunner.INVALID_ARG); } _textUI.DisplayTestFiles(new string[] { callingAssembly.GetName().Name }); _textUI.DisplayRuntimeEnvironment(); _textUI.DisplayRequestedOptions(); if (options.WaitBeforeExit && options.OutFile != null) { _textUI.DisplayWarning("Ignoring /wait option - only valid for Console"); } try { return(new TextRunner(_textUI, options).Execute(callingAssembly)); } finally { if (options.WaitBeforeExit) { _textUI.WaitForUser("Press Enter key to continue . . ."); } if (outWriter != null) { outWriter.Close(); } if (errWriter != null) { errWriter.Close(); } } }
/// <summary> /// Execute the tests in the assembly, passing in /// a list of arguments. /// </summary> /// <param name="args">Execution options</param> public int Execute(string[] args) { var options = new ConsoleOptions(args); var callingAssembly = Assembly.GetCallingAssembly(); 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 ExtendedTextWriter outWriter = null; if (options.OutFile != null) { outWriter = new ExtendedTextWrapper(new StreamWriter(Path.Combine(options.WorkDirectory, options.OutFile))); Console.SetOut(outWriter); } TextWriter errWriter = null; if (options.ErrFile != null) { errWriter = new StreamWriter(Path.Combine(options.WorkDirectory, options.ErrFile)); Console.SetError(errWriter); } var _textUI = new TextUI(outWriter, options); if (!options.NoHeader) _textUI.DisplayHeader(); if (options.ShowHelp) { _textUI.DisplayHelp(); return TextRunner.OK; } if (options.ErrorMessages.Count > 0) { _textUI.DisplayErrors(options.ErrorMessages); _textUI.DisplayHelp(); return TextRunner.INVALID_ARG; } #if !PORTABLE if (options.InputFiles.Count > 0) { _textUI.DisplayError("Input assemblies may not be specified when using the NUnitLite AutoRunner"); return TextRunner.INVALID_ARG; } #endif _textUI.DisplayTestFiles(new string[] { callingAssembly.GetName().Name }); _textUI.DisplayRuntimeEnvironment(); _textUI.DisplayRequestedOptions(); if (options.WaitBeforeExit && options.OutFile != null) _textUI.DisplayWarning("Ignoring /wait option - only valid for Console"); try { return new TextRunner(_textUI, options).Execute(callingAssembly); } finally { if (options.WaitBeforeExit) _textUI.WaitForUser("Press Enter key to continue . . ."); if (outWriter != null) outWriter.Close(); if (errWriter != null) errWriter.Close(); } }