Normally I write my unit tests in F# as
open Swensen.Unquote
open Xunit
module MyTests =
[<Fact>]
let ``SomeFunction should return 10`` () =
let a = SomeFunction()
test <@ a = 10 @>
[<Fact>]
let ``SomeOtherFunction should return 11`` () =
let a = SomeFunction()
test <@ a = 11 @>
If I wish to log to the console from xunit ( according to http://xunit.github.io/docs/capturing-output.html ) one needs to write a constructor that takes an ITestOutputHelper and then use that instead of Console.WriteLine and family.
using Xunit;
using Xunit.Abstractions;
public class MyTestClass
{
private readonly ITestOutputHelper output;
public MyTestClass(ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void MyTest()
{
var temp = "my class!";
output.WriteLine("This is output from {0}", temp);
}
}
however fsharp modules are static classes and the tests are static methods. There is no constructor to inject the output helper.
Is there a way to get access to the current output helper for the current test. I know I could rewrite my fsharp tests to be non static classes but that is undesired.
After looking at the XUnit source.
I'm pretty sure this is an overlooked case. There is no injection of the helper into static classes.