Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you mean how can you run NUnit tests programmatically (instead of using one of the supplied NUnit runners), then it's actually pretty easy:</p> <pre><code>using System; using NUnit.Core; using NUnit.Framework; using MyProject.Tests; /* assuming MyTestFixture is defined in this project/assembly */ namespace TestRunner.DemoApp { class Program { static void Main(string[] args) { var builder = new TestSuiteBuilder(); var testAssemblyLocation = typeof(MyTestFixture).Assembly.Location; var package = new TestPackage(testAssemblyLocation); var suite = builder.Build(package); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Running tests from " + testAssemblyLocation; Console.WriteLine("Testing against " + ConfigurationManager.AppSettings["HostNameSuffix"]); var result = suite.Run(new NullListener(), TestFilter.Empty); switch (result.ResultState) { case ResultState.Success: Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Pass."); break; case ResultState.Error: case ResultState.Failure: Console.ForegroundColor = ConsoleColor.Red; DrawResults(result.Results, r =&gt; r.ResultState == ResultState.Error || r.ResultState == ResultState.Failure); break; } static void DrawResults(IList results, Func&lt;TestResult, bool&gt; include) { foreach (var obj in results) { var result = obj as TestResult; if (result == null) continue; if (result.Results != null &amp;&amp; result.Results.Count &gt; 0) { DrawResults(result.Results, include); } else if (include(result)) { Console.WriteLine(result.Name); Console.WriteLine(result.Message); Console.WriteLine(result.ResultState); Console.WriteLine(result.StackTrace); Console.WriteLine(String.Empty.PadLeft(Console.WindowWidth, '=')); } } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload