0

I am struggling to be able to log to output during FsCheck.Xunit unit tests in C#. I am using ITestOutputHelper as I believe this is the recommended approach with Xunit.

In the example tests below, Test1 will not pipe "Hi" to the output but Test2 will (on latest .NET Core using Visual Studio on Windows).

Any help appreciated.

BR, Mark

public class NewTests
{
    private readonly ITestOutputHelper _output;

    public NewTests(ITestOutputHelper output)
    {
        _output = output;
    }

    [Property(Verbose = true)]
    public Property Test1()
    {
        _output.WriteLine("Hi");
        return true.ToProperty();
    }

    [Fact]
    public void Test2()
    {
        _output.WriteLine("Hi");
        Assert.Equal(1,1);
    }
}
MFL
  • 69
  • 1
  • 8
  • Test output is hard :( Perhaps related to this issue? https://github.com/fscheck/FsCheck/issues/508 – Kurt Schelfthout Apr 22 '20 at 20:28
  • Thanks for the comment, appreciated. I looked at that thread but not sure it gives me any more ideas. Seems there is no way to log output with FsCheck.Xunit at present for whatever reason. – MFL Apr 23 '20 at 22:10
  • Yes, I see. This is likely because the implementation of the PropertyAttribute in FsCheck.Xunit doesn't work with this - looks like it creates its own TestOutputHelper, maybe that one clobbers the one you are trying to use somehow. I don't really have a good solution, except you can use `Fact` to attribute your FsCheck properties, and use `Prop.ForAll` ending with `QuickCheckThrowOnFailure` to run the test. – Kurt Schelfthout Apr 25 '20 at 17:34
  • Okay, thanks for the tip, this will be useful for debugging but I don't I'll leave tests in this state normally. – MFL Apr 26 '20 at 15:27
  • It's not a bad state imo. I fairly often don't use FsCheck.Xunit but just plain FsCheck, but with xunit, and just use that API. Here is an example: https://fscheck.github.io/FsCheck/RunningTests.html#Capturing-output-when-using – Kurt Schelfthout Apr 30 '20 at 08:14
  • Okay, cheers, thanks for the reference, maybe I can move to this. – MFL May 01 '20 at 16:20

0 Answers0