问题
This question is part of larger question that can be found here
We have classes that come from Entity Framework. In other words they are not Records that are immutable they are quite posit list of mutable properties without constructor. FsCheck cannot deal with such entities out of the box and for each entity we are forced to write separate generator like so:
let BLOGen =
gen {
let! cat = Gen.choose(0, 1000)
let! opt = Gen.choose(0, 1000)
let! name = Arb.Default.String().Generator
let! dVal = Arb.Default.String().Generator
let res = new Business_Logic_Options ()
res.Category <- cat
res.UID <- opt
res.Name <- name
res.DefaultValue <- dVal
return res
}
as you can imagine that the need to write something like this can discourage people to write this kind of unit tests.
How to auto-magically generate test cases in FsCheck for C# EF entities.
来源:https://stackoverflow.com/questions/35764092/generating-random-objects-as-test-cases