gpt4 book ai didi

c# - 指定要运行的 NUnit 测试

转载 作者:可可西里 更新时间:2023-11-01 03:13:26 35 4
gpt4 key购买 nike

我有一个 NUnit 项目,它创建了一个用于运行测试的控制台应用程序。入口点如下所示:

class Program
{
[STAThread]
static void Main(string[] args)
{
string[] my_args = { Assembly.GetExecutingAssembly().Location };

int returnCode = NUnit.ConsoleRunner.Runner.Main(my_args);

if (returnCode != 0)
Console.Beep();

}
}

如果我只想运行这个测试,我可以将什么作为参数传入:

[TestFixture]
public class EmailNotificationTest
{
[Test]
public void MailerDefaultTest()
{
Assert.IsTrue(false);
}
}

显然这是受支持的,但我也不知道该怎么做。

更新

它看起来像 v3+,这可以通过 --test 选项实现,根据 the documentation .

最佳答案

最新版本 (NUnit 3) 允许调试测试并指定要执行的测试。

调试

--debug 选项启动调试器来调试测试,例如:

nunit3-console.exe "C:\path\to\the\tests.dll" --debug

过滤测试

现在您可以通过多种不同的方式来选择要运行的测试。第一个选项是 --test=NAMES。结合此选项和 ​​--debug 您可以轻松地只调试一个测试,例如:

nunit3-console.exe "C:\path\to\the\tests.dll" --debug --test="EmailNotificationTest.MailerDeSecondTest" 

如果类有命名空间,不要忘记它。

使用 --teSTList=PATH 选项,您可以运行文件中指定的所有测试,例如:

nunit3-console.exe "C:\path\to\the\tests.dll" --debug --testlist="testnames.txt" 

还有 --where=EXPRESSION 选项指示将运行哪些测试。此选项旨在扩展或替换早期的 --test--include--exclude 选项。请查看 official documentation如果您想了解有关此选项的更多信息。

关于c# - 指定要运行的 NUnit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7996050/

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