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

F#模式匹配的单元测试和断言,f#,xunit,F#,Xunit,我开始在F#打保龄球。我编写了第一个单元测试: [<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 f

我开始在F#打保龄球。我编写了第一个单元测试:

[<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)
[]
让``如果没有滚动,那么当前帧应该是第一帧`()=
let game=newGame()
让cf=currentFrame游戏
匹配
|第十帧->Assert.True(false)
|框架->
让(第一帧)=解构游戏
Assert.Equal(frame,List.item 0 firstFrames)

测试通过了,但是“Assert.True(false)”部分在我看来很难看。。。有更好的方法写吗?

来自。xunit不提供类似于
Assert.Fail()
的方法。建议使用类似于您所使用的方法的
Assert.True(false,“message”)

看,似乎没有
Assert.Fail()
方法。你的解决方案似乎很好。好的,谢谢你的链接。我希望有一种更优雅或更实用的方式来编写这样的代码。将此作为答案发布,我将接受它。has
isFalse
。您可以定义一个名称稍微好一点的函数:
让failTest msg=Assert.True(false,msg)
,然后在您的测试用例中使用它:
将cf与| TenthFrame |匹配->failTest“应该在第一帧,而不是第十帧”
感谢@s952163,我还将尝试一下Expecto