samedi 27 juin 2015

Display Output In NCrunch Test After Changing Console Ouput Stream

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)?

Aucun commentaire:

Enregistrer un commentaire