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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.