Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
696 views
in Technique[技术] by (71.8m points)

c# - 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
    }

  }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...