使用FsCheck,无法识别propertyCheck函数

时间:2015-11-29 12:25:27

标签: f# fscheck

" propertyCheck"当我尝试构建测试时,无法识别我的测试方法中引用的函数。

我认为propertyChecked是FsCheck框架的核心功能?

我需要做什么其他仪式?

module Tests.Units

open FsUnit
open NUnit.Framework
open NUnit.Core.Extensibility

open FsCheck.NUnit
open FsCheck.NUnit.Addin

let add x y = (x + y)

let commutativeProperty x y = 
    let result1 = add x y
    let result2 = add y x // reversed params
    result1 = result2

[<Test>]
let ``When I add two numbers, the result should not depend on parameter order``()=
    propertyCheck commutativeProperty |> should equal true

1 个答案:

答案 0 :(得分:2)

由于@Functional_S在评论中写入,您可以使用Check.Quick,但您应该意识到Check.Quick报告测试结果;如果该财产证明是可证伪的,它不会“失败”。在单元测试套件中,Check.QuickThrowOnFailure是一个更好的选择,因为顾名思义,它会失败。

由于看起来你试图在像NUnit这样的单元测试框架中运行属性,你应该考虑使用其中一个Glue Libraries来进行FsCheck:

这使您可以使用[<Property>]属性编写属性:

[<Property>]
let ``When I add two numbers, the result should not depend on parameter order``x y =
    let result1 = add x y
    let result2 = add y x // reversed params
    result1 = result2

由于NUnit的可扩展性差的API,你可以使用xUnit.net而不是NUnit来节省很多麻烦。