【发布时间】:2018-03-12 22:59:19
【问题描述】:
我开始在 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)
测试通过了,但是“Assert.True(false)”部分对我来说很难看...有没有更好的写法?
【问题讨论】:
-
见xunit docs 好像没有
Assert.Fail ()方法。您的解决方案似乎很好。 -
好的,谢谢你的链接。我期待一种更优雅或更实用的方式来编写这样的代码。将此作为答案发布,我会接受。
-
Expecto 拥有
isFalse。 -
您可以定义一个名称稍微好一点的函数:
let failTest msg = Assert.True(false, msg),然后在您的测试用例中使用它:match cf with | TenthFrame _ -> failTest "Should be on first frame, not tenth"