Original post

Hi all,

I am trying to figure out the best way to run a unit test for a function using a random generator. I need also that: – I don’t have to pass a generator to the function to call it each time (so I need a global generator at the package level) – the unit tests can be run in parallel (so not changing the global generator at the package level)

So my solution for now is to have a variadic argument i. e. func myfunctoTest(arg1 int, optionalGenerator ...math.Source) so that the test can pass a custom generator to the function, and the function does not need to have this optional generator argument and uses the global generator by default.

Is there a better way in your opinion? Do you see any problem with this method?

Thanks!!!

submitted by /u/dowitex
[link] [comments]