Re: How to unit test random seeds?
Eric Sosman wrote:
Patricia Shanahan wrote:
I have an application that uses two random number generator instances.
The input parameters can specify the seed for either or both of them. If
a seed is not provided in the input, I use a SecureRandom's
generateSeed().
I can obviously unit test the processing of specified seeds. The problem
is how to test my use of generateSeed(). Any ideas?
Idea (maybe not the greatest, and definitely not original):
Some features of a program are amenable to testing, others are
better suited to inspection. If your test proves that "no seed"
does in fact wind up using SecureRandom, just assume SecureRandom
does its job properly.
I do assume SecureRandom does its job properly. The question I would
like to test is whether I am using it correctly, as well as the more
general question of how to test one's use of pseudo-random features.
This thread is a last resort before declaring it untestable, at least at
the unit test level, and depending on desk check and system test
instead. At the system test level, I can check questions like whether
repeated runs without specified seeds do behave differently in the
proper ways.
Patricia