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.
In reply to Unit Testing Non-Deterministic Behaviors by friedo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |