F# 单元测试和模式匹配断言
F# unit tests and assertion on pattern matching
我开始用 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# 练习保龄球套路 (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")
。