我正在使用NUnit在C#中构建单元测试,并且我想测试主程序实际上输出正确的输出,具体取决于命令行参数.
有没有办法从NUnit测试方法,调用Program.Main(...)抓取写入Console.Out和Console.Error的所有内容,以便我可以验证它?
我在使用以下项目创建的项目中进行了以下XUnit测试dotnet new xunit:
type Scenarios(output : ITestOutputHelper) =
[<Fact>]
member __.``Output shows up`` () =
output.WriteLine("I'm here")
Run Code Online (Sandbox Code Playgroud)
这种方法似乎以前有效,但运行测试并没有显示任何输出,无论我是否使用dotnet test或dotnet xunit:
> dotnet test
Build started, please wait...
Build completed.
Test run for C:\Work\OSS\Streamstone.fs\tests\StreamstoneFs.Tests\bin\Debug\netcoreapp2.0\StreamstoneFs.Tests.dll(.NETCoreApp,Version=v2.0)
Microsoft (R) Test Execution Command Line Tool Version 15.6.0-preview-20180109-01
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
[xUnit.net 00:00:00.4295013] Discovering: StreamstoneFs.Tests
[xUnit.net 00:00:00.4750480] Discovered: StreamstoneFs.Tests
[xUnit.net 00:00:00.4792986] Starting: StreamstoneFs.Tests
[xUnit.net 00:00:00.5964013] Finished: StreamstoneFs.Tests
Total tests: …Run Code Online (Sandbox Code Playgroud)