Martin Fowler makes this easy for you. He says, "Whenever you are tempted to type something into a print statement or a debugger expression, write it as a test instead."
Here are a couple of the times that you will receive a reasonable return on your testing investment:
During Development- When you need to add new functionality to the system, write the tests first. Then, you will be done developing when the test runs.
During Debugging- When someone discovers a defect in your code, first write a test that will succeed if the code is working. Then debug until the test succeeds.
One word of caution about your tests: Once you get them running, make sure they stay running.
Ideally, you would run every test in your suite every time you change a method.
Practically, your suite will soon grow too large to run all the time. But make sure you run every test at least once a day: overnight, during lunch, during one of those long meetings…
Copyright © 1998-2009 Dilvan Moreira