我正在使用 F# 和 Xunit。(我对两者都比较陌生)
我发现当我使用 Xunit 的 Assert.Equal() 时,我需要指定"<string>"
要比较的类型何时是字符串。
例如这个运行和编译:
[<Fact>]
let Test_XunitStringAssertion() =
let s1 = "Stuff"
Assert.Equal<string>("Stuff",s1)
我的问题是,为什么我不能删除"<string>"
并只是断言"Assert.Equal("Stuff",s1)"
呢?
在我看来编译器知道这两个参数的类型,那么为什么要大惊小怪呢?
以下是编译时返回的错误Assert.Equal("Stuff",s1)
:
error FS0041: A unique overload for method 'Equal' could not be determined based on type information prior to this program point. The available overloads are shown below (or in the Error List window). A type annotation may be needed.
error FS0041: Possible overload: 'Assert.Equal<'T>(expected: 'T, actual: 'T) : unit'.
error FS0041: Possible overload: 'Assert.Equal<'T>(expected: seq<'T>, actual: seq<'T>) : unit'.
error FS0041: Possible overload: 'Assert.Equal<'T>(expected: 'T, actual: 'T, comparer: System.Collections.Generic.IEqualityComparer<'T>) : unit'.
error FS0041: Possible overload: 'Assert.Equal(expected: float, actual: float, precision: int) : unit'.
error FS0041: Possible overload: 'Assert.Equal(expected: decimal, actual: decimal, precision: int) : unit'.
error FS0041: Possible overload: 'Assert.Equal<'T>(expected: seq<'T>, actual: seq<'T>, comparer: System.Collections.Generic.IEqualityComparer<'T>) : unit'.