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'.