Back when I was a java programming I fell in love with test-first development, where you write you tests a little in advance of coding in a feature (or at least in concurrence with). I could babble on about all the benefits the approach brings, but the key to using it is that it has to be quick and easy. Unfortunately, with Drupal it is neither. But testing is possible, and still useful, since I the fragment work I am doing is kinda hairy and needs to be air-tight.
There are two major branches of automated testing; unit or white box vs functional or black box testing.
Functional testing a Drupal site means going through the browser and interacting with it as if you were a user. The best tool I have found for this is Selenium, and one of the cool things about this type of testing is that that anyone, of any level of experience can help out.
Unit testing is focused and developer driven. Each feature of your code should have a couple of unit tests that exercises it in isolation of the rest of the system. Here is where you test different failure states and edge cases. Every time you discover a bug, you should create a unit test that reliably triggers it, then fix the bug and verify that the test now passes. This is your best defense against regression. The cliche is that if a feature does not have a test, it doesn't exist. Of course, by that standard Drupal doesn't exist at all. As far as I know, the best tool for unit testing Drupal is the SimpleTest module (http://drupal.org/project/simpletest) that Moshe built around Last Craft's Simple Test Framework (http://www.lastcraft.com/simple_test.php)
I can't think of a single open source Java project that does not come with JUnit, and Rails has testing baked in, but SimpleTest seems to be something of a red-heading step-child in the Drupal word. Moshe did a good chunk of work getting Drupal and Simple Test to work together, and spent a while pushing it, but it never seemed to gain traction. There isn't even an offical 5x version, although HEAD does work.
Sorry for the ranting. I actually meant to blog about some cool SimpleTest/Drupal tips, but I will break those into another post.