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

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...