Generating random objects as test cases

会有一股神秘感。 提交于 2019-12-10 11:46:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!