1

Here is one of my unit tests:

[<NCrunch.Framework.Isolated>]
let [<Test>] ``inputX test`` () =
    let simulator = Simulator(@"H:\MyProj\Inputs" @@ @"inputX.txt",false)
    use sw = new StringWriter() in Console.SetOut(sw)
    simulator.Run()
    let expected, actual =
        File.ReadAllText(@"H:\MyProj\Inputs" @@ @"inputX.out").Replace("\r",""),
        sw.ToString()
    StringAssert.Contains(expected, actual)

I do printfn's throughout the simulator code, and as long as the test doesn't pass, NCrunch will show the output in its output window.

I want to display information after the assert but I can't figure out how to do it and can't seem to find a simple answer.

I guess maybe I would need something like

Console.Set(NCrunchEnvironment.OuputStream)
printfn "%A" stuff

but that doesn't exist.

Will I have to create a new process for the simulator and "catch" the output that way? Or maybe pass a stream to the simulator (or return one from it)?

1 Answers1

0

NCrunch doesn't do anything magic I don't think, I believe it just registeres a trace listener and outputs messages that appear in the trace stream whilst the tests are running.

I'm no F# expert but in C# we just use the Trace.WriteLine method and NCrunch will display whatever you put there. I think you should be able to use the same class in F#

Sam Holder
  • 32,535
  • 13
  • 101
  • 181