如何抑制 NUnit 控制台输出?

How can I suppress NUnit console output?

有没有办法抑制控制台输出中显示的 NUnit 错误和故障?

我尝试使用命令行选项:/xml、/out、/err。但我仍然在控制台中得到输出。

从您对 /xml 选项的使用,我可以看出您使用的是旧版本的 NUnit,但是,对于新版本的答案也是一样的。

无法更改控制台运行器生成的报告输出。您可以将整个内容重定向到一个文件,甚至重定向到空设备,但您不能抑制它的一部分。

NUnit3 中,您可以这样定义 SetupFixture

[SetUpFixture]
public class TestSetup
{
    [OneTimeSetUp]
    public void RunBeforeAnyTests()
    {
        // Disable console output from test methods
        Console.SetOut(TextWriter.Null);
    }

    [OneTimeTearDown]
    public void RunAfterAnyTests()
    {
        // Whatever should run after tests
    }
}