Just some thoughts, mostly for my own benefit. I reserve the right to change my mind, and even do complete U-turns where necessary.
- Use CruiseControl, or some other form of continuous integration.
- Use clover, and fail checkins if there is any code not covered by a unit test.
- Block System.out.println with a CVS commit script.
- Ban unit tests from hitting the database.
- Don’t write tests that require more than 10 lines of (non production) setup code per test method.
- Don’t write code that requires a (JUnit) setUp method that is bigger than all your test methods combined.
- Use mock objects very sparingly. Consider them indications of code smell.
- Don’t use anonymous subclasses in testcases just to loosen method permissions for testing, or to stub out hard-to-test behaviour. Code smell warning.
- Do put your test code in a parallel directory structure, in the same packages as your production code.
- Do test protected and package methods.
- Don’t worry about testing private methods too much – they must be called from a public, package or protected method, or they’re redundant and can be deleted.