haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
668 stars 96 forks source link

Make FsCheck tests use custom generators registered by Arb.Register. #201

Closed teo-tsirpanis closed 6 years ago

teo-tsirpanis commented 7 years ago

Currently, using custom generators requires creating a custom function that injects the new Arbitrarys to the config. I guess it can be done easier.

AnthonyLloyd commented 7 years ago

If you register a type with Arb.Register currently will it not just work?

teo-tsirpanis commented 7 years ago

No. I made a generator that rises an exception and registered it. No luck.

AnthonyLloyd commented 7 years ago

There must be some default on the real FsCheck config that we not including when we recreate it.

thinkbeforecoding commented 6 years ago

My current way to do it is to override testProperty:

let testPropertyWithConfig c n t =
    testPropertyWithConfig { 
        c with 
            arbitrary = 
                [ typeof<Arbs>
                  typeof<LongStringPassword>] } n t

let testProperty n t = testPropertyWithConfig FsCheckConfig.defaultConfig n t

A workaround, but still better than nothing...

AnthonyLloyd commented 6 years ago

I do this anyway with my common set of arbs and don't use Register.

I'm adding some code later I'll take a look.

AnthonyLloyd commented 6 years ago

I've taken a quick look at FsCheck code. Its nothing to do with the config being incorrect. My guess at the moment is Arb.Register isn't being called.

Will look at this later more today/tomorrow.

AnthonyLloyd commented 6 years ago

@teo-tsirpanis @thinkbeforecoding If you take a look at the fscheck issue fscheck/FsCheck#413 I raised this gives some explanation as to why Arb.register<_> doesn't work.

I could add an Expecto.register<_> and apply it to the test config but it looks like FsCheck is moving away from this kind of global state.

I think the example code above is a good solution and can be extended to give different Arbs per test grouping. It's personally what I do and don't think of it as a workaround.

Let me know what you think.