为什么我在基于属性的测试中收到"无参数提供"错误?

Sco*_*rod 2 f# nunit-2.5 fscheck

以下测试失败:

open FsCheck
open FsCheck.NUnit
open NUnit.Framework

let ``Property: double negation equals no negation`` list =
    list = List.rev (List.rev list)

[<Test>]
let ``reversing list two times is equal to not reversing list at all`` list = 
    Check.Quick ``Property: double negation equals no negation``
Run Code Online (Sandbox Code Playgroud)

错误:

消息:未提供任何参数

我认为FsCheck会在每次测试迭代时为我提供论据.

我正在引用以下文档.

Mar*_*ann 5

这是一个适用于xUnit.net的版本:

open FsCheck
open Xunit

let ``Property: double negation equals no negation`` list =
    list = List.rev (List.rev list)

[<Fact>]
let ``reversing list two times is equal to not reversing list at all`` () = 
    Check.Quick ``Property: double negation equals no negation``
Run Code Online (Sandbox Code Playgroud)

当你以这种方式使用它时,第一个函数是属性,它可以带参数.

[<Fact>]-annotated功能没有参数.

该方法的问题在于,Check.Quick如果属性不成立,则不会导致测试失败.它只输出该财产被伪造.如果您希望测试失败,如果属性是伪造的,您应该使用Check.QuickThrowOnFailure:

open FsCheck
open Xunit

let ``Property: double negation equals no negation`` list =
    list = List.rev (List.rev list)

[<Fact>]
let ``reversing list two times is equal to not reversing list at all`` () = 
    Check.QuickThrowOnFailure ``Property: double negation equals no negation``
Run Code Online (Sandbox Code Playgroud)

另一个问题是,没有理由以这种冗长的方式写这个.这是一种更紧凑的方式来编写相同的属性:

open FsCheck
open Xunit

[<Fact>]
let ``reversing list two times is equal to not reversing list at all`` () = 
    Check.QuickThrowOnFailure <| fun (l : int list) ->
        l = List.rev (List.rev l)
Run Code Online (Sandbox Code Playgroud)