I've never read any books on the subject, but one thing I like to do is, when a bug is found, ask yourself, "What's a test that would have detected this bug?" Then write that test. Run your new test and make sure that it fails. Then fix the bug. After that, re-run the test to make sure it passes. Finally, check-in both test and patch.