gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:37:45 25 4
gpt4 key购买 nike

我经常想执行快速测试,并在 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) {
<b>return new AutoRun(Assembly.GetExecutingAssembly())
.Execute(new String[] {"/test:Runner.Foo.TestSomething"});</b>
}

[TestFixture]
public class Foo {

[Test]
public void TestSomething() {
// test something
}
}

}

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

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

关于c# - 以编程方式运行 NUnit 测试夹具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45310571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com