当我试图构建测试时,无法识别在我的测试方法中引用的"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发布于 2015-11-29 13:47:27
正如@Functional_S在评论中所写的,您可以使用Check.Quick,尽管您应该认识到,Check.Quick只报告测试结果;如果该属性被证明是可伪造的,则不会“失败”。在单元测试套件中,Check.QuickThrowOnFailure是一个更好的选择,因为顾名思义,它会在失败时抛出。
由于您似乎试图在像NUnit这样的单元测试框架中运行属性,所以您应该考虑使用Glue库中的一个用于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可以省去很多麻烦。
https://stackoverflow.com/questions/33982731
复制相似问题