我开始用 F# 打保龄球型 ( 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)”部分对我来说看起来很难看......有更好的方法来编写它吗?
最佳答案
来自docs 。 xunit 不提供像 Assert.Fail ()
这样的方法。建议使用类似于您所做的方式的 Assert.True (false, "message")
。
关于F# 单元测试和模式匹配断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46515912/