How to restrict the number of test with stest/check

227 views
Skip to first unread message

Burt

unread,
Aug 3, 2016, 10:34:11 AM8/3/16
to Clojure
Hi,

(stest/check `myfunc) runs very, very long

so i tried

(stest/check `myfunc {:num-tests 2})

but unfortunately that does not restrict the number of test.

Can anybody help?

Kind regards, Burt

Alex Miller

unread,
Aug 3, 2016, 2:46:32 PM8/3/16
to Clojure
As the docstring for check notes:

"The opts map includes the following optional keys, where stc
aliases clojure.spec.test.check:

::stc/opts  opts to flow through test.check/quick-check
:gen        map from spec names to generator overrides"

So the opts map would be like:

(stest/check `myfunc {:clojure.spec.test.check/opts {:num-tests 2}})

Burt

unread,
Aug 4, 2016, 1:51:23 AM8/4/16
to Clojure
Thanks!

Chris Shellenbarger

unread,
Mar 7, 2018, 10:43:32 AM3/7/18
to Clojure
Alex, 
     When I attempt to specify :num-tests, ie: 

(stest/check `do-something {:clojure.spec.test.check/opts {:num-tests 10}})

It usually seems to work, but sometimes I can see code executing far more than the number of tests I've specified.  This appears to be correlated to when it finds an error - but I usually don't know that until after the test run has completed.  Is this a case of spec attempting to 'shrink' the input to arrive at the cause of the problem?

I am running the command from the repl and so maybe that impacts it?  However, even with summarize-results it feels like the effect would be the same.  Is there a different way that I'm supposed to consume this lazy sequence generated by stest/check?

Thanks!
Chris

Alex Miller

unread,
Mar 7, 2018, 1:26:07 PM3/7/18
to Clojure
Yes, check will attempt to shrink when an error is found.
Reply all
Reply to author
Forward
0 new messages