///// <summary> ///// Count Test Cases using a filter ///// </summary> ///// <param name="filter">The filter to apply</param> ///// <returns>The number of test cases found</returns> //public int CountTestCases(TestFilter filter) //{ // return this.suite.CountTestCases(filter); //} /// <summary> /// Run selected tests and return a test result. The test is run synchronously, /// and the listener interface is notified as it progresses. /// </summary> /// <param name="listener">Interface to receive EventListener notifications.</param> /// <param name="filter">A test filter used to select tests to be run</param> /// <returns></returns> public ITestResult Run(ITestListener listener, ITestFilter filter) { TestExecutionContext context = new TestExecutionContext(); if (this.settings.Contains("WorkDirectory")) { context.WorkDirectory = (string)this.settings["WorkDirectory"]; } else #if NETCF || SILVERLIGHT { context.WorkDirectory = Env.DocumentFolder; } #else { context.WorkDirectory = Environment.CurrentDirectory; } #endif context.Listener = listener; WorkItem workItem = loadedTest.CreateWorkItem(filter, finallyDelegate); workItem.Execute(context); while (workItem.State != WorkItemState.Complete) { System.Threading.Thread.Sleep(5); } return(workItem.Result); }
internal static void Run(string title, Stream outputStream) { var suite = new TestSuite(title); var builder = new NUnitLiteTestAssemblyBuilder(); suite.Add(builder.Build(System.Reflection.Assembly.GetExecutingAssembly(), new Dictionary<string, object>())); var testExecutionContext = TestExecutionContext.CurrentContext; testExecutionContext.WorkDirectory = Environment.CurrentDirectory; #if __IOS__ var workItem = suite.CreateWorkItem(TestFilter.Empty, new FinallyDelegate()); #else var workItem = suite.CreateWorkItem(TestFilter.Empty); #endif workItem.Execute(testExecutionContext); var testWriter = new NUnitLite.Runner.NUnit2XmlOutputWriter(DateTime.Now); using (var writer = new StreamWriter(outputStream)) { testWriter.WriteResultFile(workItem.Result, writer); } }
///// <summary> ///// Count Test Cases using a filter ///// </summary> ///// <param name="filter">The filter to apply</param> ///// <returns>The number of test cases found</returns> //public int CountTestCases(TestFilter filter) //{ // return this.suite.CountTestCases(filter); //} /// <summary> /// Run selected tests and return a test result. The test is run synchronously, /// and the listener interface is notified as it progresses. /// </summary> /// <param name="listener">Interface to receive EventListener notifications.</param> /// <param name="filter">A test filter used to select tests to be run</param> /// <returns></returns> public ITestResult Run(ITestListener listener, ITestFilter filter) { TestExecutionContext context = new TestExecutionContext(); if (this.settings.Contains("WorkDirectory")) { context.WorkDirectory = (string)this.settings["WorkDirectory"]; } else #if NETCF || SILVERLIGHT || PORTABLE { context.WorkDirectory = Env.DocumentFolder; } #else { context.WorkDirectory = Environment.CurrentDirectory; } #endif context.Listener = listener; WorkItem workItem = loadedTest.CreateWorkItem(filter); workItem.Execute(context); #if PORTABLE while (workItem.State != WorkItemState.Complete) { long endTime = DateTime.Now.Ticks + TimeSpan.TicksPerMillisecond * 20; while (endTime > DateTime.Now.Ticks) { ; } } #else while (workItem.State != WorkItemState.Complete) { System.Threading.Thread.Sleep(5); } #endif return(workItem.Result); }