简体   繁体   English

以编程方式运行NUnit测试夹具

[英]Run NUnit test fixture programmatically

I often want to perform a quick test, and code it up in LINQPad. 我经常想要进行快速测试,并在LINQPad中编写代码。

So I have a Main() entry point. 所以我有一个Main()入口点。 Can I make NUnit "run" a fixture programmatically from there? 我可以从那里以编程方式让NUnit“运行”一个夹具吗?

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 : 您可以使用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. 这里"/run:Runner.Foo"指定文本夹具。

Mind that you have to reference the nunitlite.dll package as well. 请注意,您还必须引用nunitlite.dll包。

With 3.8, the problem that was introduced in 3.7 will be fixed. 使用3.8时,3.7中引入的问题将得到修复。 Whether that works explicitly with LINQPad, I'm not sure. 是否与LINQPad明确地工作,我不确定。 You could try it out using the latest build from our MyGet feed. 您可以使用MyGet Feed中的最新版本进行试用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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