Unit testing a method that can have random behaviour -


i ran across situation afternoon, thought i'd ask guys do.

we have randomized password generator user password resets , while fixing problem it, decided move routine (slowly growing) test harness.

i want test passwords generated conform rules we've set out, of course results of function randomized (or, well, pseudo-randomized).

what guys in unit test? generate bunch of passwords, check pass , consider enough?

a unit test should same thing every time runs, otherwise may run situation unit test fails occasionally, , real pain debug.

try seeding pseudo-randomizer same seed every time (in test, is--not in production code). way test generate same set of inputs every time.

if can't control seed , there no way prevent function testing being randomized, guess stuck unpredictable unit test. :(


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -