私はF#とXunitを使用しています。私はXunitのAssert.Equal()を使用すると、比較対象の型が文字列の場合に"<string>"
を指定する必要があることがわかりました。例えばF#は、Xunitを使用して文字列に同等性をアサートするときにタイプ情報が必要です
この実行のとコンパイル:
[<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'.
関連:http://stackoverflow.com/questions/5667372/what-unit-testing-frameworks-are-available-for-f/5669263#5669263(つまり、劇的に過小に公表されている慣用的なF#アサーション) –