I need to test a class that use random.nextDouble() is there elegant way to provide the test these number so to be able to foresee the executed output?
I'd recommend to embed random numbers generator into separate component and inject it into your class. Thus, you would be able to inject its mocked instance in tests. It's the most elegant solution in my opinion. You can also do some tricks with reflection and override random generator created within class body but this is not recommended at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With