public void LoadTests(IList <string> files) { if (IsPackageLoaded) { UnloadTests(); } _files = files; _events.FireTestsLoading(files); _package = MakeTestPackage(files); Runner = _testEngine.GetRunner(_package); Tests = new TestNode(Runner.Explore(TestFilter.Empty)); Results.Clear(); _events.FireTestLoaded(Tests); foreach (var subPackage in _package.SubPackages) { Services.RecentFiles.SetMostRecent(subPackage.FullName); } }
public void LoadTests(IList <string> files) { if (IsPackageLoaded) { UnloadTests(); } _files = files; _package = MakeTestPackage(files); Runner = _testEngine.GetRunner(_package); Tests = new TestNode(Runner.Explore(TestFilter.Empty)); _resultIndex.Clear(); if (TestLoaded != null) { TestLoaded(new TestNodeEventArgs(TestAction.TestLoaded, Tests)); } foreach (var subPackage in _package.SubPackages) { RecentFiles.SetMostRecent(subPackage.FullName); } }
private static void ListTests(string directoryToSearch) { using (ITestEngine testEngine = TestEngineActivator.CreateInstance()) { Console.WriteLine("In test engine instance"); var files = Directory.GetFiles(directoryToSearch, "*.dll", SearchOption.AllDirectories); Console.WriteLine($"Found {files.Count()} to search"); TestPackage package = new TestPackage(files); Console.WriteLine("Test package created"); using (ITestRunner runner = testEngine.GetRunner(package)) { Console.WriteLine("In runner"); var testSuites = runner.Explore(TestFilter.Empty); var testCases = testSuites.SelectNodes("//test-case"); foreach (XmlNode n in testCases) { Console.WriteLine(n.Attributes["fullname"].Value); } } } }
public static void Main(string[] args) { var path = Assembly.GetExecutingAssembly().Location; var package = new TestPackage(path); package.AddSetting("WorkDirectory", Environment.CurrentDirectory); using (ITestEngine engine = TestEngineActivator.CreateInstance()) { var filterService = engine.Services.GetService <ITestFilterService>(); var builder = filterService.GetTestFilterBuilder(); var testPlan = getTestPlan(); if (testPlan != null) { foreach (var testCase in testPlan.Tests) { builder.AddTest(testCase.Selector); } } var filter = builder.GetFilter(); using (ITestRunner runner = engine.GetRunner(package)) { runner.Run(listener: null, filter: filter); } } }
public void RunTests() { ITestEngine engine = TestEngineActivator.CreateInstance(); var package = new TestPackage(TestAssemblyPath); ITestRunner runner = engine.GetRunner(package); runner.Run(NunitListener, TestFilter.Empty); }
private int RunTests(TestPackage package, TestFilter filter) { // TODO: We really need options as resolved by engine for most of these DisplayRequestedOptions(); // TODO: Incorporate this in EventCollector? RedirectOutputAsRequested(); TestEventHandler eventHandler = new TestEventHandler(options, outWriter, errorWriter); XmlNode result = null; // Save things that might be messed up by a bad test TextWriter savedOut = Console.Out; TextWriter savedError = Console.Error; DateTime startTime = DateTime.Now; try { using (new ColorConsole(ColorStyle.Output)) #if true result = engine.Run(package, eventHandler, filter); #else using (ITestRunner runner = engine.GetRunner(package)) { if (runner.Load(package)) { engineResult = runner.Run(eventHandler, testFilter); } } #endif } finally { Console.SetOut(savedOut); Console.SetError(savedError); RestoreOutput(); } //Console.WriteLine(); ResultReporter reporter = new ResultReporter(result, options); reporter.ReportResults(); // TODO: Inject this? var outputManager = new OutputManager(result, this.workDirectory); foreach (var outputSpec in options.ResultOutputSpecifications) { outputManager.WriteResultFile(outputSpec, startTime); } return(reporter.Summary.ErrorsAndFailures); }
public TestDriver(string path) { TestPackage package = new TestPackage(path); ITestEngine engine = TestEngineActivator.CreateInstance(); var _filterService = engine.Services.GetService <ITestFilterService>(); ITestFilterBuilder builder = _filterService.GetTestFilterBuilder(); EmptyFilter = builder.GetFilter(); TestRunner = engine.GetRunner(package); }
private TestResults RunTests(TestPackage package, TestFilter filter, Messages.OnMessage[] messageSubscribers) { XmlNode result; using (new SaveConsoleOutput()) using (ITestRunner runner = _engine.GetRunner(package)) using (var ms = new MemoryStream()) using (var output = CreateOutputWriter(ms)) { try { var labels = "ON"; var eventHandler = new TestEventHandler(output, labels, messageSubscribers); result = runner.Run(eventHandler, filter); var reporter = new ResultReporter(result, output, _options); reporter.ReportResults(); output.Flush(); if (reporter.Summary.UnexpectedError) { return(new TestResults(TestResults.Code.UnexpectedError, GetResultText(ms), reporter.Summary)); } return(new TestResults(reporter.Summary.InvalidAssemblies > 0 ? TestResults.Code.InvalidAssembly : GetCode(reporter.Summary.FailureCount + reporter.Summary.ErrorCount + reporter.Summary.InvalidCount), GetResultText(ms), reporter.Summary)); } catch (NUnitEngineException ex) { output.WriteLine(ex.Message); output.Flush(); return(new TestResults(TestResults.Code.InvalidArg, GetResultText(ms))); } catch (FileNotFoundException ex) { output.WriteLine(ex.Message); output.Flush(); return(new TestResults(TestResults.Code.InvalidAssembly, GetResultText(ms))); } catch (DirectoryNotFoundException ex) { output.WriteLine(ex.Message); output.Flush(); return(new TestResults(TestResults.Code.InvalidAssembly, GetResultText(ms))); } catch (Exception ex) { output.WriteLine(ex.ToString()); output.Flush(); return(new TestResults(TestResults.Code.UnexpectedError, GetResultText(ms))); } } }
public TestEventListener( ITestEngine engine, TestPackage package, ConcurrentQueue <ReportItem> reportItems, string threadName ) { _reportItems = reportItems; Runner = engine.GetRunner(package); _threadName = threadName; }
public static XmlNode DoWork(string assemblyName) { var assembly = AssemblyLoadContext.Default.Assemblies.First(x => x.GetName().Name == assemblyName); ITestEngine engine = TestEngineActivator.CreateInstance(); TestPackage package = new TestPackage(assembly.Location); package.Settings[FrameworkPackageSettings.RunOnMainThread] = true; ITestRunner runner = engine.GetRunner(package); return(runner.Run(Listener, TestFilter.Empty)); }
private int ExploreTests(TestPackage package, TestFilter filter) { XmlNode result; using (var runner = _engine.GetRunner(package)) result = runner.Explore(filter); if (_options.ExploreOutputSpecifications.Count == 0) { _resultService.GetResultWriter("cases", null).WriteResultFile(result, Console.Out); } else { foreach (OutputSpecification spec in _options.ExploreOutputSpecifications) { _resultService.GetResultWriter(spec.Format, new object[] { spec.Transform }).WriteResultFile(result, spec.OutputPath); } } return(ConsoleRunner.OK); }
static void Main(string[] args) { ITestEngine engine = TestEngineActivator.CreateInstance(); ITestFilterService _filterService = engine.Services.GetService <ITestFilterService>(); TestPackage package = new TestPackage(Assembly.GetExecutingAssembly().Location); package.AddSetting("WorkDirectory", Environment.CurrentDirectory); using (ITestRunner runner = engine.GetRunner(package)) { ITestFilterBuilder builder = _filterService.GetTestFilterBuilder(); XmlNode result = runner.Run(null, builder.GetFilter()); } }
private int ExploreTests(TestPackage package, TestFilter filter) { XmlNode result = null; using (var runner = _engine.GetRunner(package)) result = runner.Explore(filter); if (_options.ExploreOutputSpecifications.Count == 0) { new TestCaseOutputWriter().WriteResultFile(result, Console.Out); } else { var outputManager = new OutputManager(result, _workDirectory); foreach (OutputSpecification spec in _options.ExploreOutputSpecifications) { outputManager.WriteTestFile(spec); } } return(ConsoleRunner.OK); }
public XmlNode Run(ITestEventListener listener, string[] nameFilter, string path, string suiteName, string[] supportAssemblies, string testRunnerType, string testRunnerAssembly) { InitSupportAssemblies(supportAssemblies); TestFilter filter = TestFilter.Empty; if (nameFilter != null && nameFilter.Length > 0) { filter = CreateTestFilter(nameFilter); } ITestRunner tr = null; if (!string.IsNullOrEmpty(testRunnerType)) { Type runnerType; if (string.IsNullOrEmpty(testRunnerAssembly)) { runnerType = Type.GetType(testRunnerType, true); } else { var asm = Assembly.LoadFrom(testRunnerAssembly); runnerType = asm.GetType(testRunnerType); } tr = (ITestRunner)Activator.CreateInstance(runnerType); } TestPackage package = CreatePackage(path); if (tr == null) { tr = engine.GetRunner(package); } return(tr.Run(listener, filter)); }
public void LoadTests(TestPackage package) { if (IsPackageLoaded) { UnloadTests(); } //if (TestLoading != null) // TestLoading(new TestEventArgs(TestAction.TestLoading)); _package = package; try { Runner = _testEngine.GetRunner(package); // TODO: Error here when multiple files are run Tests = new TestNode(Runner.Explore(TestFilter.Empty)); _resultIndex.Clear(); } catch (Exception ex) { //if (TestException != null) // TestException(new TestEventArgs(TestAction.TestLoadFailed, ex)); } if (TestLoaded != null) { TestLoaded(new TestEventArgs(TestAction.TestLoaded, Tests)); } // TODO: Handle this on the presenter? foreach (var subPackage in _package.SubPackages) { RecentFiles.SetMostRecent(subPackage.FullName); } }
public static void Main(string[] args) { RunnerOptions opts = null; try { opts = ParseOptions(args); } catch (OptionException e) { Console.WriteLine(e.Message); Console.WriteLine("Try running with '--help' for more information."); Environment.Exit(1); } RecordingListener listener = new RecordingListener(opts.reportFile); ITestEngine engine = TestEngineActivator.CreateInstance(); TestPackage package = new TestPackage(opts.targetAssembly); ITestRunner runner = engine.GetRunner(package); int testCount = runner.CountTestCases(TestFilter.Empty); if (testCount < 1) { throw new ArgumentException("Nothing to run, no tests were loaded"); } try { DateTime startTime = DateTime.Now; for (int i = 0; i < opts.iterations; i++) { runner.Run(listener, TestFilter.Empty); TimeSpan offset = DateTime.Now - startTime; if (opts.durationLimit > 0 && offset.TotalSeconds > opts.durationLimit) { break; } } } finally { listener.CloseFile(); } Environment.Exit(0); }
public void RunTests() { ITestEngine engine = TestEngineActivator.CreateInstance(); TestSuite mTestSuite = null; ITestEventListener listner = null; //EventListener li = new NullListener(); Console.WriteLine("Created amazonSqsClient"); Console.WriteLine("App Config path:" + AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); var message = testQueue.Get(); if (message == null) return; // if count greater than 3 then delete message if (int.Parse(message.Attributes["ApproximateReceiveCount"]) > 3) testQueue.DeleteMessage(queue.QueueUrl, message.ReceiptHandle); var testmodel = JsonConvert.DeserializeObject<TestModel>(message.Body); Environment.SetEnvironmentVariable("env.testConfig", JsonConvert.SerializeObject(testmodel.ConfigModel)); // if test assembly does not exists delete message if(File.Exists(testmodel.ConfigModel.TestAssembly)) testQueue.DeleteMessage(message); TestPackage package = TestPackage(testmodel.ConfigModel.TestAssembly); AppConfig.Change(package.FullName + ".config"); TestPackage package = new TestPackage(testmodel.ConfigModel.TestAssembly); mTestSuite = new TestSuiteBuilder().Build(package); amazonSqsClient.DeleteMessage(queue.QueueUrl, message.ReceiptHandle); Console.WriteLine("-> starting tests ...."); Console.WriteLine("-> Tests:" + testmodel.ConfigModel.TestAssembly); Console.WriteLine("-> Category:" + testmodel.Category); ITestFilter testFilter = new CategoryFilter(testmodel.Category); ITestRunner runner = engine.GetRunner(package); XmlNode result = runner.Run(, testFilter); TestResult result = mTestSuite.Run(li, testFilter); Thread.Sleep(5000); }
/// <summary> /// Create the nUnit test runner. /// </summary> public ITestRunner CreateTestRunner(string assemblyPath) { ITestRunner result = null; ITestEngine engine = CreateTestEngine(assemblyPath); var dir = Path.GetDirectoryName(assemblyPath); TestPackage testPackage = new TestPackage(assemblyPath); //https://github.com/nunit/nunit-console/blob/master/src/NUnitEngine/nunit.engine/EnginePackageSettings.cs string processModel = "InProcess"; string domainUsage = "None"; testPackage.AddSetting(EnginePackageSettings.ProcessModel, processModel); testPackage.AddSetting(EnginePackageSettings.DomainUsage, domainUsage); testPackage.AddSetting(EnginePackageSettings.WorkDirectory, dir); result = engine.GetRunner(testPackage); return(result); }
static void Main(string[] args) { using (ITestEngine testEngine = TestEngineActivator.CreateInstance()) { var files = Directory.GetFiles(ConfigurationManager.AppSettings["directoryToSearch"], "*.dll", SearchOption.AllDirectories); TestPackage package = new TestPackage(files); using (ITestRunner runner = testEngine.GetRunner(package)) { var testSuites = runner.Explore(TestFilter.Empty); var testCases = testSuites.SelectNodes("//test-case"); foreach (XmlNode n in testCases) { Console.WriteLine(n.Attributes["fullname"].Value); } } } }
static void Main(string[] args) { // set up the options string path = Assembly.GetExecutingAssembly().Location; TestPackage package = new TestPackage(path); package.AddSetting("WorkDirectory", Environment.CurrentDirectory); // prepare the engine ITestEngine engine = TestEngineActivator.CreateInstance(); var _filterService = engine.Services.GetService <ITestFilterService>(); ITestFilterBuilder builder = _filterService.GetTestFilterBuilder(); TestFilter emptyFilter = builder.GetFilter(); using (ITestRunner runner = engine.GetRunner(package)) { // execute the tests XmlNode result = runner.Run(null, emptyFilter); } }
/// <summary> /// Create the nUnit test runner. /// </summary> private ITestRunner CreateTestRunner() { ITestRunner result = null; ITestEngine engine = CreateTestEngine(); TestPackage testPackage = new TestPackage(TestAssembly); //https://github.com/nunit/nunit-console/blob/master/src/NUnitEngine/nunit.engine/EnginePackageSettings.cs string processModel = "InProcess"; string domainUsage = "None"; testPackage.AddSetting(EnginePackageSettings.ProcessModel, processModel); testPackage.AddSetting(EnginePackageSettings.DomainUsage, domainUsage); result = engine.GetRunner(testPackage); var agency = engine.Services.GetService <TestAgency>(); agency?.StopService(); return(result); }
/// <summary> Runs the tests. </summary> /// <returns> The Results of the test run. </returns> public TestRunnerResults Run() { using ITestEngine nunitEngine = TestEngineActivator.CreateInstance(); nunitEngine.WorkDirectory = this.runnerSettings.TestAssemblyFullPath; var package = new TestPackage(this.runnerSettings.TestAssemblyFullName); package.AddSetting("WorkDirectory", $"{this.runnerSettings.TestAssemblyFullPath} PATH"); var filter = this.GetTestFiter(nunitEngine); using var runner = nunitEngine.GetRunner(package); // Run all the tests in the assembly var testListener = new DefaultTestEventListener(); var testResult = runner.Run(testListener, filter); var deserializedTestResults = Deserialize <TestRun>(testResult); System.Console.WriteLine(deserializedTestResults.TestSuites[0].Total); return(new TestRunnerResults(true, TestRunnerType.NUnit)); }
protected void Page_Load(object sender, EventArgs e) { // set up the options string path = Assembly.GetExecutingAssembly().Location; TestPackage package = new TestPackage(path); package.AddSetting("ProcessModel", "Single"); package.AddSetting("DomainUsage", "None"); // prepare the engine ITestEngine engine = TestEngineActivator.CreateInstance(); var _filterService = engine.Services.GetService <ITestFilterService>(); ITestFilterBuilder builder = _filterService.GetTestFilterBuilder(); TestFilter emptyFilter = builder.GetFilter(); using (ITestRunner runner = engine.GetRunner(package)) { // execute the tests XmlNode result = runner.Run(null, emptyFilter); lblTest.Text = result.InnerText; } }
private ITestRunner CreateTestRunner() { ITestRunner result = null; try { mEngine = CreateTestEngine(); TestPackage testPackage = new TestPackage(TestAssembly); //https://github.com/nunit/nunit-console/blob/master/src/NUnitEngine/nunit.engine/EnginePackageSettings.cs string processModel = "InProcess"; string domainUsage = "None"; testPackage.AddSetting(EnginePackageSettings.ProcessModel, processModel); testPackage.AddSetting(EnginePackageSettings.DomainUsage, domainUsage); result = mEngine.GetRunner(testPackage); } catch (Exception e) { MessageBox.Show(e.ToString(), "NUnit Engine", MessageBoxButton.OK, MessageBoxImage.Error); } return(result); }
public TestRun Perform(string assemblyName) { TestRun testRun = null; ITestEventListener listener = new TestEventDispatcher(); // Get an interface to the engine ITestEngine engine = TestEngineActivator.CreateInstance(); // Create a simple test package - one assembly, no special settings TestPackage package = new TestPackage(assemblyName); // Get a runner for the test package ITestRunner runner = engine.GetRunner(package); // Run all the tests in the assembly XmlNode testResult = runner.Run(listener, TestFilter.Empty); //string report = string.Empty; //listener.OnTestEvent(report); //var doc = new XmlDocument(); //var node = doc.ImportNode(testResult, true); //doc.AppendChild(node); //doc.Save("output.xml"); using (TextReader sr = new StringReader(testResult.OuterXml)) { var serializer = new XmlSerializer(typeof(TestRun)); testRun = (TestRun)serializer.Deserialize(sr); } //Console.WriteLine(testResult.OuterXml); return(testRun); }
public static void Main(string[] args) { var path = Assembly.GetExecutingAssembly().Location; var package = new TestPackage(path); package.AddSetting("WorkDirectory", Environment.CurrentDirectory); using (ITestEngine engine = TestEngineActivator.CreateInstance()) { var filterService = engine.Services.GetService <ITestFilterService>(); var builder = filterService.GetTestFilterBuilder(); builder.AddTest("NUnitTestRunner.Class1.Test123"); builder.AddTest("NUnitTestRunner.Class1.Test456"); var filter = builder.GetFilter(); using (ITestRunner runner = engine.GetRunner(package)) { var result = runner.Run(listener: null, filter: filter); } } }
public static XmlNode FullRun(List <string> projectAssemblies, string category) { XmlNode node = null; foreach (string assemblyPath in projectAssemblies) { if (engine == null) { engine = TestEngineActivator.CreateInstance(); } TestPackage testPackage = new TestPackage(assemblyPath); var filterService = engine.Services.GetService <ITestFilterService>(); var builder = filterService.GetTestFilterBuilder(); builder.SelectWhere(category); TestFilter filter = builder.GetFilter(); ITestRunner runner = engine.GetRunner(testPackage); var y = runner.CountTestCases(filter); node = runner.Run(testEventListner, filter); //TestRun testRun = RunManagerNunit.DeserializeTestRun(node); } return(node); }
private ConsoleTestRunnerResult RunTests(TestPackage package) { var labels = (_options.DisplayTestLabels ?? LabelsOutputMode.On).ToString().ToUpperInvariant(); XmlNode?result = null; NUnitEngineUnloadException?unloadException = null; NUnitEngineException? engineException = null; try { using (new SaveConsoleOutput()) using (var runner = _engine.GetRunner(package)) { var eventHandler = new TestEventHandler(_outWriter, labels); var testFilter = new TestFilterBuilder().GetFilter(); result = runner.Run(eventHandler, testFilter); } } catch (NUnitEngineUnloadException ex) { unloadException = ex; } catch (NUnitEngineException ex) { engineException = ex; } if (result != null) { var reporter = new ResultReporter(result, _outWriter, _options); reporter.ReportResults(); if (engineException != null) { _outWriter.WriteLine(ColorStyle.Error, Environment.NewLine + ExceptionHelper.BuildMessage(engineException)); return(new ConsoleTestRunnerResult(new UnexpectedError(engineException))); } if (unloadException != null) { _outWriter.WriteLine(ColorStyle.Warning, Environment.NewLine + ExceptionHelper.BuildMessage(unloadException)); } if (reporter.Summary.UnexpectedError) { return(new ConsoleTestRunnerResult(default(UnexpectedError))); } if (reporter.Summary.InvalidAssemblies > 0) { return(new ConsoleTestRunnerResult(default(InvalidAssembly))); } if (reporter.Summary.InvalidTestFixtures > 0) { return(new ConsoleTestRunnerResult(default(InvalidTestFixture))); } var failureCount = reporter.Summary.FailureCount + reporter.Summary.ErrorCount + reporter.Summary.InvalidCount; if (failureCount == 0) { return(new ConsoleTestRunnerResult(new SomeFailures(reporter.Summary))); } return(new ConsoleTestRunnerResult(new AllSuccess(reporter.Summary))); } // If we got here, it's because we had an exception, but check anyway if (engineException != null) { _outWriter.WriteLine(ColorStyle.Error, ExceptionHelper.BuildMessage(engineException)); _outWriter.WriteLine(); _outWriter.WriteLine(ColorStyle.Error, ExceptionHelper.BuildMessageAndStackTrace(engineException)); } return(new ConsoleTestRunnerResult(new UnexpectedError(engineException))); }
public override void Initialize() { var path = Path.Combine(Player.Core.GetPath(AimpCorePathType.Plugins), "AimpTestRunner"); _logWriter = new StreamWriter(Path.Combine(path, "integration.tests.log")); try { AppDomain.CurrentDomain.SetData("APPBASE", path); Environment.CurrentDirectory = path; _testResultFile = Path.Combine(path, "integration.tests.xml"); if (Player.Win32Manager.GetAimpHandle() == IntPtr.Zero) { _logWriter.WriteLine("Unable to run test. This is not AIMP."); _logWriter.Flush(); _logWriter.Close(); Terminate(); } _engine = TestEngineActivator.CreateInstance(); _engine.WorkDirectory = path; _engine.Initialize(); TestPackage package = new TestPackage(Path.Combine(path, "AimpTestRunner_plugin.dll")); package.Settings.Add("ProcessModel", "Single"); ITestRunner runner = _engine.GetRunner(package); AimpTestContext.Instance.AimpPlayer = Player; Player.ServiceMessageDispatcher.Hook(new Hook((type, i, arg3) => { if (type == AimpCoreMessageType.EventLoaded && !_inProgress) { _inProgress = true; try { XmlNode testResult = runner.Run(this, TestFilter.Empty); _resultWriter.CheckWritability(_testResultFile); _resultWriter.WriteResultFile(testResult, _testResultFile); var reporter = new ResultReporter(testResult, new ExtendedTextWrapper(_logWriter)); reporter.ReportResults(); } catch (Exception e) { _logWriter.WriteLine(e.ToString()); } finally { _logWriter.Flush(); Terminate(); } } return(new AimpActionResult(ActionResultType.OK)); })); } catch (Exception e) { _logWriter.WriteLine(e.ToString()); _logWriter.Flush(); _logWriter.Close(); Terminate(); } }