friedo has asked for the wisdom of the Perl Monks concerning the following question:
I have a web application with a "click here if you forgot your password" feature. When clicked, it generates a new, random password and emails it to the user. It's time to write some unit tests.
I can test that the email gets properly generated by using Test::MockObject to make a mock MIME::Lite so I don't have to really send an email. However, I can't think of a good way to test the password-generating function itself.
The random password function is quite simple. It picks a random word from a file and then sticks a random three-digit number on the end. How do I write a test that can tell the difference between a "good" random result, and something erroneous? I could regex the result and check if it looks right, but that seems like a cop-out.
Lest you think this concern is trivial, it is only a small example. I have several other non-deterministic behaviors which are more complex and do require some more rigorous testing. I wanted to start with this example so I have some ideas about how to proceed with the harder ones.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unit Testing Non-Deterministic Behaviors
by Zaxo (Archbishop) on Jun 11, 2007 at 04:08 UTC | |
|
Re: Unit Testing Non-Deterministic Behaviors
by tirwhan (Abbot) on Jun 11, 2007 at 08:58 UTC | |
by ww (Archbishop) on Jun 11, 2007 at 10:41 UTC | |
by friedo (Prior) on Jun 11, 2007 at 14:58 UTC | |
by tirwhan (Abbot) on Jun 11, 2007 at 16:19 UTC | |
|
Re: Unit Testing Non-Deterministic Behaviors
by GrandFather (Saint) on Jun 11, 2007 at 04:06 UTC | |
|
Don't reinvent the wheel
by nferraz (Monk) on Jun 11, 2007 at 16:53 UTC |