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

我经常想要进行快速测试,并在LINQPad中进行编码。

所以我有一个Main()入口点。 我可以从那里以编程方式让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 } } } 

您可以使用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 } } } 

这里"/run:Runner.Foo"指定文本夹具。

请注意,您还必须引用nunitlite.dll包。

使用3.8时,3.7中引入的问题将得到修复。 是否与LINQPad明确合作,我不确定。 您可以使用MyGet Feed中的最新版本进行尝试。