0

The "propertyCheck" function that is referenced within my test method is NOT recognized when I attempt to build my test.

I thought that propertyChecked was a core function of the FsCheck framework?

What other ceremony do I need to perform?

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
4

1 回答 1

2

As @Functional_S writes in the comment, you can use Check.Quick, although you should realise that Check.Quick only reports test results; it doesn't 'fail' if the property turns out to be falsifiable. In a unit test suite, Check.QuickThrowOnFailure is a better option, because, as the name implies, it'll throw on failure.

Since it looks like you're attempting to run properties from within a unit testing framework like NUnit, you should consider to instead use one of the Glue Libraries for FsCheck:

This would enable you to write properties using the [<Property>] attribute:

[<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

Due to the poor extensibility API for NUnit, you can save yourself a lot of grief using xUnit.net instead of NUnit.

于 2015-11-29T13:47:27.213 回答