使用 FsCheck,无法识别 propertyCheck 函数
Using FsCheck, the propertyCheck function is NOT recognized
当我尝试构建我的测试时,无法识别我的测试方法中引用的 "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
正如@Functional_S在评论中所写,你可以使用Check.Quick
,虽然你应该意识到Check.Quick
只报告测试结果;它不会 'fail' 如果 属性 结果是可证伪的。在单元测试套件中,Check.QuickThrowOnFailure
是更好的选择,因为顾名思义,它会抛出失败。
由于您似乎正试图从像 NUnit 这样的单元测试框架中 运行 属性,因此您应该考虑改为使用 FsCheck 的 Glue 库之一:
这将使您能够使用 [<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 来避免很多麻烦。
当我尝试构建我的测试时,无法识别我的测试方法中引用的 "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
正如@Functional_S在评论中所写,你可以使用Check.Quick
,虽然你应该意识到Check.Quick
只报告测试结果;它不会 'fail' 如果 属性 结果是可证伪的。在单元测试套件中,Check.QuickThrowOnFailure
是更好的选择,因为顾名思义,它会抛出失败。
由于您似乎正试图从像 NUnit 这样的单元测试框架中 运行 属性,因此您应该考虑改为使用 FsCheck 的 Glue 库之一:
这将使您能够使用 [<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 来避免很多麻烦。