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

标签 f# xunit

我开始用 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/

相关文章:

asp.net-core - 使用 OpenCover 运行 XUnit 和 FluentAssertions 会出现错误消息

c# - 如何从 C# 可移植类库 (PCL) 添加对 F# 可移植库的引用

.net - 如何在 F# 中枚举枚举/类型

msbuild - vstest.console.exe 未生成 trx 文件,TestResults 为空

c# - 如何使用 WebApplicationFactory 在 TestServer 中切换服务?

c# - 使用 XUnit Assert 函数比较两个 List<T>

f# - 如何使用 F# 根据给定的数据创建一棵树

f# - 计算泛型类型的运行平均值

.net-4.0 - 如何在 F# 的 printf 格式字符串中放入文字百分号 (%)?

gitlab-ci - 如何在 Gitlab CI 中捕获结构化的 xUnit 测试输出?