haskell-hedgehog icon indicating copy to clipboard operation
haskell-hedgehog copied to clipboard

Tests without generators

Open chris-martin opened this issue 8 years ago • 12 comments

So, Hedgehog is a property testing library, yes, but - It's also just a really great general-purpose test runner, and I've been using it for things that aren't actually property tests. The downside is that my tests run a hundred times, when they only need to run once.

Is there a quick way to modify a property so that it only checks once?

And, I don't know if this is reasonable to ask, but: Could Hedgehog be clever enough to detect whether a property ever uses a generator, and only recheck if it does?

chris-martin avatar Oct 05 '17 19:10 chris-martin

I’d typically use the “once” function to just run a property that doesn’t use generators. Though it doesn’t seem the function is in hedgehog like it was in Jack.

Not sure about adding detection of tests that don’t use generator.

On Fri, 6 Oct 2017 at 6:17 am, Chris Martin [email protected] wrote:

So, Hedgehog is a property testing library, yes, but - It's also just a really great general-purpose test runner, and I've been using it for things that aren't actually property tests. The downside is that my tests run a hundred times, when they only need to run once.

Is there a quick way to modify a property so that it only checks once?

And, I don't know if this is reasonable to ask, but: Could Hedgehog be clever enough to detect whether a property ever uses a generator, and only recheck if it does?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hedgehogqa/haskell-hedgehog/issues/121, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKbuQKbD8eF5gSF3tj-RIy7Y9P7Y8TCks5spStfgaJpZM4PvkSl .

tmcgilchrist avatar Oct 05 '17 20:10 tmcgilchrist

The combinator is withTests 1, e.g. https://github.com/hedgehogqa/haskell-hedgehog/blob/d12b3e8d2150cd51e4ea89b1bb1727a3beceed2f/hedgehog-example/test/Test/Example/Basic.hs#L42

nhibberd avatar Oct 05 '17 20:10 nhibberd

Cheers, I thought it'd be there somewhere.

On Fri, Oct 6, 2017 at 7:59 AM, Nick Hibberd [email protected] wrote:

The combinator is withTests 1, e.g. https://github.com/hedgehogqa/ haskell-hedgehog/blob/d12b3e8d2150cd51e4ea89b1bb1727 a3beceed2f/hedgehog-example/test/Test/Example/Basic.hs#L42

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hedgehogqa/haskell-hedgehog/issues/121#issuecomment-334590407, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKbuTztZOUjfA5Hu3KlyiBafcfWs_Mnks5spUMsgaJpZM4PvkSl .

tmcgilchrist avatar Oct 05 '17 21:10 tmcgilchrist

Why not make once an alias to withTests 1 then?

kindaro avatar Oct 05 '17 21:10 kindaro

I guess I figured having once was redundant, I tried not to have multiple ways of doing the same thing is all.

jacobstanley avatar Oct 05 '17 22:10 jacobstanley

And, I don't know if this is reasonable to ask, but: Could Hedgehog be clever enough to detect whether a property ever uses a generator, and only recheck if it does?

I can imagine this could possibly be added in to the Test monad but I'm not sure if it's worth the complexity.

jacobstanley avatar Oct 05 '17 22:10 jacobstanley

I don't mind not having a once function in hedgehog, but if it doesn't I think the withTests documentation should discuss this use case to make the solution more discoverable via search.

chris-martin avatar Oct 05 '17 22:10 chris-martin

Yeah I completely agree

jacobstanley avatar Oct 05 '17 22:10 jacobstanley

Fwiw, I would add once if enough people wanted it, but I've been trying to keep the API as thin as possible initially so that we don't grow a bunch of unnecessary functions that end up not being widely used.

jacobstanley avatar Oct 05 '17 22:10 jacobstanley

Having once seems pretty special case to me. Having better discoverability on the right way to do this in hedgehog would be better IMHO

On Fri, 6 Oct 2017 at 9:21 am, Jacob Stanley [email protected] wrote:

Fwiw, I would add once if enough people wanted it, but I've been trying to keep the API as thin as possible initially so that we don't grow a bunch of unnecessary functions that end up not being widely used.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/hedgehogqa/haskell-hedgehog/issues/121#issuecomment-334608402, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKbufLM5SfOPTNXv3ADgUs2tS8RBF-Zks5spVZwgaJpZM4PvkSl .

tmcgilchrist avatar Oct 05 '17 22:10 tmcgilchrist

Just found this issue while wondering the same.

To me, something like the once function feels quite helpful. Writing withTests 1 is easy enough, but it does look and feel wrong. It seems like the API is telling me that I'm doing something hacky or unsupported. I've never noticed the comment added to withTests that would have told me this is actually the intended way to achieve this functionality.

I'm a big proponent of property-based testing, but in practice I continue to write a lot of example-based tests, so from my perspective its quite valuable for this not to be too awkward to achieve.

(Background: I use Hedgehog a lot at work (we're quite happy with it!) where we have some utility definitions that accomplish this. Now I'm adding it to a personal project and noticing this as a friction/confusion point.)

fieldstrength avatar Mar 01 '20 13:03 fieldstrength

I use Hedgehog a lot at work (we're quite happy with it!)

:+1: :heart_eyes:

where we have some utility definitions that accomplish this

:thinking: say we add once, then another request comes in for adding twice (or similar). Where do we draw the line?

In 88% of the cases we do come up with some utility functions, and I think that's where once belongs. It's like some sort of a rather special case for a property-based testing library.

In general though, just exposing a single way of doing things makes the API easier to learn for newcomers, and (often) explicit is better than implicit.

moodmosaic avatar Mar 01 '20 16:03 moodmosaic