我如何在 Expecto 上注册我自己的 FsCheck 生成器
How do I register my own FsCheck Generator on Expecto
我构建了生成三的倍数的生成器类型。我想在 Expecto 的测试中使用它。如何注册此生成器并告诉我的测试使用它?
let multipleOfThree n = n * 3
type ThreeGenerator =
static member ThreeMultiple() =
Arb.generate<NonNegativeInt>
|> Gen.map (fun (NonNegativeInt n) -> multipleOfThree n)
|> Gen.filter (fun n -> n > 0)
|> Arb.fromGen
我找到了自己的答案。在 Expecto
中注册你的生成器
let multipleOfThree =
{ FsCheckConfig.defaultConfig with
arbitrary = [ typeof<ThreeGenerator> ] }
并且可以在你的测试中使用
testPropertyWithConfig multipleOfThree "test with your generator "
<| fun x -> Expect.equal (FunctionUnderTest x) "Expected" "Error message"
我构建了生成三的倍数的生成器类型。我想在 Expecto 的测试中使用它。如何注册此生成器并告诉我的测试使用它?
let multipleOfThree n = n * 3
type ThreeGenerator =
static member ThreeMultiple() =
Arb.generate<NonNegativeInt>
|> Gen.map (fun (NonNegativeInt n) -> multipleOfThree n)
|> Gen.filter (fun n -> n > 0)
|> Arb.fromGen
我找到了自己的答案。在 Expecto
中注册你的生成器 let multipleOfThree =
{ FsCheckConfig.defaultConfig with
arbitrary = [ typeof<ThreeGenerator> ] }
并且可以在你的测试中使用
testPropertyWithConfig multipleOfThree "test with your generator "
<| fun x -> Expect.equal (FunctionUnderTest x) "Expected" "Error message"