grokky
grokky

Reputation: 9255

Run NUnit test fixture programmatically

I often want to perform a quick test, and code it up in LINQPad.

So I have a Main() entry point. Can I make NUnit "run" a fixture programmatically from there?

using NUnit.Framework;

public class Runner
{

  public static void Main()
  {
    //what do I do here?
  }

  [TestFixture]
  public class Foo
  {

    [Test]
    public void TestSomething()
    {
      // test something
    }

  }

}

Upvotes: 5

Views: 2950

Answers (2)

Charlie
Charlie

Reputation: 13681

With 3.8, the problem that was introduced in 3.7 will be fixed. Whether that works explicitly with LINQPad, I'm not sure. You could try it out using the latest build from our MyGet feed.

Upvotes: 3

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476503

You can use the NUnitLite Runner:

using NUnit.Framework;
using NUnitLite;

public class Runner {


    public static int Main(string[] args) {
        return new AutoRun(Assembly.GetExecutingAssembly())
                       .Execute(new String[] {"/test:Runner.Foo.TestSomething"});
    }

    [TestFixture]
    public class Foo {

        [Test]
        public void TestSomething() {
            // test something
        }
    }

}

Here "/run:Runner.Foo" specifies the text fixture.

Mind that you have to reference the nunitlite.dll package as well.

Upvotes: 5

Related Questions