F#XUnit测试不打印输出

Tom*_*han 7 f# xunit

我在使用以下项目创建的项目中进行了以下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 testdotnet 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: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 1.1835 Seconds

> dotnet xunit
Detecting target frameworks in StreamstoneFs.Tests.fsproj...
Building for framework netcoreapp2.0...
  StreamstoneFs -> C:\Work\OSS\Streamstone.fs\src\StreamstoneFs\bin\Debug\netstandard2.0\StreamstoneFs.dll
  StreamstoneFs.Tests -> C:\Work\OSS\Streamstone.fs\tests\StreamstoneFs.Tests\bin\Debug\netcoreapp2.0\StreamstoneFs.Tests.dll
Running .NET Core 2.0.0 tests for framework netcoreapp2.0...
xUnit.net Console Runner (64-bit .NET Core 4.6.00001.0)
  Discovering: StreamstoneFs.Tests
  Discovered:  StreamstoneFs.Tests
  Starting:    StreamstoneFs.Tests
  Finished:    StreamstoneFs.Tests
=== TEST EXECUTION SUMMARY ===
   StreamstoneFs.Tests  Total: 1, Errors: 0, Failed: 0, Skipped: 0, Time: 0.109s
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

Sco*_*son 5

这适用于带有 .NET Core 项目的 VS Code,尽管它有点嘈杂:

dotnet test --logger:"console;verbosity=detailed"
Run Code Online (Sandbox Code Playgroud)


Max*_*Max 3

仅当单元测试失败时,我才能显示输出:

type StackOverflow(output : ITestOutputHelper) = 

    [<Fact>]
    member __.``Output shows up`` () =
        output.WriteLine("hello world, from output")
        printfn "Hello world, from printfn!"
        Assert.True(false)
Run Code Online (Sandbox Code Playgroud)

这将给出以下输出:

Failed   Tests+StackOverflow.Output shows up
Error Message:
 Assert.True() Failure
Expected: True
Actual:   False
Stack Trace:
   at Tests.StackOverflow.Output shows up() in C:\git\dotnetTesting\Tests.fs:line 17
Standard Output Messages:
 hello world, from output
Run Code Online (Sandbox Code Playgroud)

无论测试结果如何,输出printfn都不会显示。如果测试通过,那么输出也永远不会显示。

文档来看,输出似乎是为调试而设计的,所以这是有道理的。在我看来,dotnet 命令行工具并没有像 Visual Studio 在其示例中那样捕获输出。