F#单元测试和模式匹配的断言



我开始在f#做保龄球kata(http://codingdojo.org/kata/bowling/)。我写了第一个单元测试:

[<Fact>]
let ``If no roll was made then the current frame should be the first one`` () =
    let game = newGame()
    let cf = currentFrame game
    match cf with
    | TenthFrame _ -> Assert.True(false)
    | Frame frame ->
        let (firstFrames, _) = deconstructGame game
        Assert.Equal (frame, List.item 0 firstFrames)

测试通过了,但是" astert.true(false)"部分对我来说似乎很丑陋...有没有更好的写作方法?

来自文档。Xunit不提供诸如Assert.Fail ()之类的方法。建议是使用与您所做方式相似的Assert.True (false, "message")

最新更新