How to capture output with XUnit 2.0 and FSharp style tests

China☆狼群 提交于 2019-12-05 01:43:12
Tomas Petricek

If xUnit does not have any alternative mechanism for injection of the parameters, then I guess the only option is to define the tests as methods in an F# object type. I also prefer writing tests as functions using let, but the following simple object type does not look too bad:

open Swensen.Unquote
open Xunit
open Xunit.Abstractions

type MyTests(output:ITestOutputHelper) =

    [<Fact>]
    member __.``SomeFunction should return 10`` () =
        let a = SomeFunction()
        output.WriteLine("Some function returned {0}", a)
        test <@ a = 10 @>

It would be nice if xUnit supported some other option for this - I suspect that they might be open to suggestions, if it is something that would not be too awkward (perhaps using a method parameter?)

But unless xUnit adds support for some other method, I think you'll need to use F# object with methods.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!