以编程方式运行NUnit测试治具 [英] Run NUnit test fixture programmatically
本文介绍了以编程方式运行NUnit测试治具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我经常想执行一个快速测试,并在LINQPad中进行编码.
I often want to perform a quick test, and code it up in LINQPad.
所以我有一个 Main()
入口点.我可以让NUnit从那里以编程方式运行"灯具吗?
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
}
}
}
推荐答案
您可以使用 NUnitLite Runner :
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
}
}
}
此处"/run:Runner.Foo"
指定文本固定装置.
Here "/run:Runner.Foo"
specifies the text fixture.
请记住,您还必须引用 nunitlite.dll
包.
Mind that you have to reference the nunitlite.dll
package as well.
这篇关于以编程方式运行NUnit测试治具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文