简体   繁体   中英

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
    }

  }

}

You can use the NUnitLite Runner :

using NUnit.Framework;
using NUnitLite;

public class Runner {


    public static int Main(string[] args) {
        
    }

    [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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM