2

我已经构建了生成三的倍数的生成器类型。我想在 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
4

1 回答 1

1

我找到了我的自我。在 Expecto 中注册您的生成器

    let multipleOfThree =
    { FsCheckConfig.defaultConfig with
          arbitrary = [ typeof<ThreeGenerator> ] }

并且可以在您的测试中使用

testPropertyWithConfig multipleOfThree "test with your generator "
          <| fun x -> Expect.equal (FunctionUnderTest x) "Expected" "Error message"
于 2020-07-13T08:42:52.093 回答