/// <summary> /// Initializes a new instance of the <see cref="TextUI"/> class. /// </summary> /// <param name="writer">The TextWriter to use.</param> /// <param name="listener">The Test listener to use.</param> public TextUI(TextWriter writer, ITestListener listener) { // Set the default writer - may be overridden by the args specified this.writer = writer; this.runner = new NUnitLiteTestAssemblyRunner(new NUnitLiteTestAssemblyBuilder()); this.listener = listener; }
public void SetUp() { TestUtilities.SimpleEventRecorder.Clear(); builder = new DefaultTestAssemblyBuilder(); runner = new NUnitTestAssemblyRunner(builder); }
public static IEnumerable <FailedTest> GetFailedTests(ITestAssemblyRunner testRunner, Type testsType) { var testResult = RunTests(testRunner, testsType); Debug.Assert(testResult != null); return(GetFailedTestsFromTestResult(testResult)); }
private static ImplementationStatus[] RunIncorrectImplementationsTests(ITestAssemblyRunner testRunner) { Console.WriteLine("Ловим баги...\r\n"); var incorrectImplementations = AssemblyHelper.GetIncorrectImplementationTypes <ICoffeeMachine>(AssemblyHelper.CoffeeMachineAssembly); return(GetIncorrectImplementationsResults(testRunner, incorrectImplementations).ToArray()); }
/// <summary> /// Initializes a new instance of the <see cref="TestPage"/> class. /// </summary> public TestPage() { InitializeComponent(); this.runner = new DefaultTestAssemblyRunner(new DefaultTestAssemblyBuilder()); this.callingAssembly = Assembly.GetCallingAssembly(); this.writer = new TextBlockWriter(this.ScratchArea); }
/// <summary> /// Initializes a new instance of the <see cref="TextUI"/> class. /// </summary> /// <param name="writer">The TextWriter to use.</param> public TextUI(TextWriter writer) { // Set the default writer - may be overridden by the args specified this.writer = writer; #if SILICONSTUDIO_PLATFORM_IOS this.runner = new NUnitLiteTestAssemblyRunner(new NamespaceAssemblyBuilder(new NUnitLiteTestAssemblyBuilder()), new FinallyDelegate()); #else this.runner = new NUnitLiteTestAssemblyRunner(new NamespaceAssemblyBuilder(new NUnitLiteTestAssemblyBuilder())); #endif }
public void CreateRunner() { _mockAssemblyPath = Path.Combine(TestContext.CurrentContext.TestDirectory, MOCK_ASSEMBLY); _slowTestsPath = Path.Combine(TestContext.CurrentContext.TestDirectory, SLOW_TESTS); #if NUNITLITE _runner = new NUnitLiteTestAssemblyRunner(new DefaultTestAssemblyBuilder()); #else _runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); #endif }
public void TestGetTestAssemblyRunnerWithAssemblyNullReturnsNull() { NUnitSuite suite = new NUnitSuite("suite-name"); suite.Add(typeof(TestFixtureStubOne).Assembly); ITestAssemblyRunner runner = suite.GetTestAssemblyRunner(null); Assert.IsNull(runner); }
/// <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); } }
public void SetUp() { TestUtilities.SimpleEventRecorder.Clear(); builder = new DefaultTestAssemblyBuilder(); #if NUNITLITE runner = new NUnitLiteTestAssemblyRunner(builder); #else runner = new NUnitTestAssemblyRunner(builder); #endif }
public void TestGetTestAssemblyRunnerWithAssemblyAddedReturnsTestAssemblyRunner() { NUnitSuite suite = new NUnitSuite("suite-name"); Assembly assembly = typeof(TestFixtureStubOne).Assembly; suite.Add(assembly); ITestAssemblyRunner runner = suite.GetTestAssemblyRunner(assembly); Assert.IsNotNull(runner); }
public void CreateRunner() { _runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); _testStartedCount = 0; _testFinishedCount = 0; _successCount = 0; _failCount = 0; _skipCount = 0; _inconclusiveCount = 0; }
/// <summary> /// Initializes a new instance of the <see cref="TextUI"/> class. /// </summary> /// <param name="writer">The TextWriter to use.</param> /// <param name="listener">The Test listener to use.</param> public TextUI(TextWriter writer, ITestListener listener) { // Set the default writer - may be overridden by the args specified this.writer = writer; this.finallyDelegate = new FinallyDelegate(); this.runner = new NUnitLiteTestAssemblyRunner(new NUnitLiteTestAssemblyBuilder(), this.finallyDelegate); this.listener = listener; AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(this.TopLevelHandler); }
public void CreateRunner() { _mockAssemblyPath = Path.Combine(TestContext.CurrentContext.TestDirectory, MOCK_ASSEMBLY); _slowTestsPath = Path.Combine(TestContext.CurrentContext.TestDirectory, SLOW_TESTS); _runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); _testStartedCount = 0; _testFinishedCount = 0; _successCount = 0; _failCount = 0; _skipCount = 0; _inconclusiveCount = 0; }
/// <summary> /// Run selected tests synchronously or asynchronously, notifying the listener interface as it progresses. /// </summary> /// <param name="assemblies">The list of test assembly runners to run.</param> /// <param name="listener">Interface to receive EventListener notifications.</param> /// <param name="filter">A test filter used to select tests to be run.</param> /// <param name="runAsync"><c>true</c> to run tests asynchronously, otherwise <c>false</c> to run synchronously.</param> /// <param name="results">The <see cref="ITestResult" /> object to add the test results to.</param> private static void RunTests(IList <ITestAssemblyRunner> assemblies, ITestListener listener, ITestFilter filter, bool runAsync, ref TestSuiteResult results) { filter = ValidateFilter(filter); Queue <ITestAssemblyRunner> testQueue = new Queue <ITestAssemblyRunner>(assemblies); // Check each test not ran when first encountered to see if it is ready to be run while (testQueue.Count > 0) { // Run test if not currently running, otherwise queue up to be checked again later ITestAssemblyRunner test = testQueue.Dequeue(); if (!test.IsTestRunning) { if (runAsync) { test.RunAsync(listener, filter); } else { test.Run(listener, filter); } } else { // Test not ready to run so re-enqueue testQueue.Enqueue(test); } // Slow down the polling loop to give time for tests to complete if (runAsync) { Thread.Sleep(10); } } // Wait for tests to complete while (assemblies.Any(test => test.IsTestRunning || !test.IsTestComplete)) // Slow down the polling loop to give time for tests to complete { Thread.Sleep(10); } // Add individual test runner results to overall result foreach (ITestAssemblyRunner test in assemblies) { if (test.Result != null) { results.AddResult(test.Result); } } }
/// <inheritdoc /> protected override ITestAssemblyRunner CreateTestAssemblyRunner() { // Return base functionality if (RunnerToLoad == null) { return(base.CreateTestAssemblyRunner()); } // Return custom runner ITestAssemblyRunner runner = RunnerToLoad; RunnerToLoad = null; return(runner); }
public void CreateRunner() { _runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); _suiteStartedCount = 0; _suiteFinishedCount = 0; _testStartedCount = 0; _testFinishedCount = 0; _testOutputCount = 0; _successCount = 0; _failCount = 0; _skipCount = 0; _inconclusiveCount = 0; _activeTests = new Dictionary <string, bool>(); }
private static bool TestsAreValid(ITestAssemblyRunner testRunner) { Console.WriteLine("Проверяем, что все тесты проходят на эталонной CoffeeMachine..."); var failed = TestRunningHelpers.GetFailedTests(testRunner, typeof(CoffeeMachineTestsTask)).ToList(); if (failed.Any()) { Console.WriteLine( "Тесты не в порядке. На эталонной CoffeeMachine не прошли: " + string.Join(", ", failed.Select(x => x.ToString(ShouldPrintDebugInfo)))); return(false); } Console.WriteLine("Тесты в порядке."); return(true); }
/// <inheritdoc /> public ITestResult GetTestResults(Assembly assembly) { if (assembly == null) { throw ExceptionHelper.ThrowArgumentNullException(nameof(assembly)); } lock (TestSuite) { TestSuiteResult results = new TestSuiteResult(TestSuite); ITestAssemblyRunner runner = TestSuite.GetTestAssemblyRunner(assembly); if (runner?.Result != null) { results.AddResult(runner.Result); } return(results); } }
private void RunTests(ITestFilter testFilter) { MissingAPILambdaFunctions.Initialize(); ITestAssemblyRunner runner = null; if (Utils.IsIL2CPP) { runner = new NUnitTestAssemblyRunner(new UnityTestAssemblyBuilder()); } else { runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); } var currentAssembly = this.GetType().Assembly; var options = new Dictionary <string, string>(); var tests = runner.Load(currentAssembly, options); var testListener = new TestListener(); var result = runner.Run(testListener, testFilter); TestDriver.Instance.OnTestFinished(this.HttpClient, testListener.FailedTestsCases); }
/// <summary> /// Loads and adds a test to the suite. /// </summary> /// <remarks> /// Check the returned test for null or the <see cref="ITest.RunState" /> to make sure that the test has been /// loaded and added. /// </remarks> /// <param name="assembly">The assembly to load and add.</param> /// <param name="settings">Dictionary of options to use in loading the test.</param> /// <returns> /// An <see cref="ITest" /> representing the loaded tests, or <c>null</c> if the assembly is already loaded or the /// load failed. /// </returns> /// <exception cref="ArgumentNullException"><see cref="assembly" /> is <c>null</c>.</exception> public ITest Add(Assembly assembly, IDictionary <string, object> settings = null) { if (assembly == null) { throw ExceptionHelper.ThrowArgumentNullException(nameof(assembly)); } if (ContainsAssembly(assembly)) { return(GetTestAssemblyRunner(assembly).LoadedTest); } // Empty settings if null if (settings == null) { settings = new Dictionary <string, object>(); } ITestAssemblyRunner runner = CreateTestAssemblyRunner(); // Test will be null if not loaded or marked as invalid Test test = LoadTest(runner, assembly, settings); if (test == null) { return(null); } if (test.RunState == RunState.NotRunnable) { return(test); } // Add test and runner if correctly loaded v_Assemblies.Add(assembly, runner); Add(test); return(test); }
private static IEnumerable <ImplementationStatus> GetIncorrectImplementationsResults( ITestAssemblyRunner testRunner, IEnumerable <Type> implementations) { var implTypeToTestsType = AssemblyHelper.GetIncorrectImplementationTests() .ToDictionary(t => { t.SetUp(); return(t.CoffeeMachine.GetType()); }, t => t.GetType()); foreach (var implementation in implementations) { var isSecret = implementation.HasAttribute <SecretAttribute>(); var failed = TestRunningHelpers.GetFailedTests(testRunner, implTypeToTestsType[implementation]) .ToArray(); yield return(new ImplementationStatus( implementation.Name, failed, IncorrectImplementationAttribute.GetDescription(implementation), isSecret)); } }
/// <inheritdoc /> public async Task <ITestResult> GetTestResultsAsync(Assembly assembly) { if (assembly == null) { throw ExceptionHelper.ThrowArgumentNullException(nameof(assembly)); } Task <ITestResult> task = Task.Run(() => { lock (TestSuite) { TestSuiteResult results = new TestSuiteResult(TestSuite); ITestAssemblyRunner runner = TestSuite.GetTestAssemblyRunner(assembly); if (runner?.Result != null) { results.AddResult(runner.Result); } return((ITestResult)results); } }); return(await task.ConfigureAwait(false)); }
/// <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 }
/// <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 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(); } } }
/// <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) { // 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(); } } } }
public PortableUI(ITestListener listener, Assembly testAssembly) { this.runner = new NUnitLiteTestAssemblyRunner(new NUnitLiteTestAssemblyBuilder()); this.listener = listener; this.testAssembly = testAssembly; }
/// <summary> /// Initializes a new instance of the <see cref="TextUI"/> class. /// </summary> /// <param name="writer">The TextWriter to use.</param> public TextUI(TextWriter writer) { // Set the default writer - may be overridden by the args specified this.writer = writer; this.runner = new DefaultTestAssemblyRunner(new DefaultTestAssemblyBuilder()); }
// 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 Driver() { runner = new NUnitLiteTestAssemblyRunner(new NUnitLiteTestAssemblyBuilder(), finallyDelegate); stream = new TcpClient(ADDRESS, PORT).GetStream(); }
/// <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 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(); } } } }