如何在FsCheck中注册任意实例并让xUnit使用它? [英] How do I register an Arbitrary instance in FsCheck and have xUnit use it?
本文介绍了如何在FsCheck中注册任意实例并让xUnit使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类型为Average
的字段,count
是一个正数int64
,另一个是double
字段,称为sum
.
I've got a type Average
with a field count
that's a positive int64
and a double
field called sum
.
我随意设置了一个生成有效实例的条件
I made an arbitrary that generates valid instances with
let AverageGen = Gen.map2 (fun s c -> Average(float(s),int64(int(c))) (Arb.Default.NormalFloat().Generator) (Arb.Default.PositiveInt().Generator) |> Arb.fromGen
在xUnit中的Property
样式测试中,如何获取平均值类型的参数?
How do I get this to be generate arguments with type Average in Property
style tests in xUnit?
[<Property>]
static member average_test(av:Average) = ...
推荐答案
type Generators =
static member TestCase() =
{ new Arbitrary<TestCase>() with
override x.Generator =
gen { ...
return TestCase(...) }}
[<Property(Arbitrary=[|typeof<Generators>|])>]
这篇关于如何在FsCheck中注册任意实例并让xUnit使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文