Tips on JUnit style
Create your test hierarchy around what the code does, not how it is
structured. Write tests for behaviors, not methods. A test
method should test a single behavior.
Keep test methods small. Ideally each test case has a single assert.
TestCase is a mechanism for fixture reuse. So if you have a VideoList
class, create separate TestCases for testing empty list behavior and
testing full list behavior; TestEmptyList and TestFullList.
(You'll also want OneItemList and a FullMinusOneItemList test cases -
boundary value analysis.)
Don't put tests in same folder has code being tested - put in a subpackage or parallel package.
Use the message argument so when your test fails it gives a meaningful
message. If you do this you don't have to include a comment
explaining what the test does.
Keep tests independent of each other. Ideally only one test should fail at a time.
Use assertEquals() instead of assertTrue() to make your intent
more clear and to be sure you are comparing object values and not
references.
Create small, focused interfaces to your classes to make it easier to create and maintain "mock" implementations.
Avoid System.out and System.err in your tests. Tests should be
automated and not rely on visual inspection of output by a human tester.
Avoid testing against databases and network resources (e.g. sockets). Use an interface and a mock.
Add a main() method that runs the test in TestRunner.
Start by writing what you are testing: the assert. Then work
backward and fill in whatever is needed to set things up for the assert.
Always write a toString() method to improve failure reporting.
Refactor your tests! Avoid duplication of code in your tests as well as in the production code.
Run coverage tool often to see what you might be missing.
There should be at least as much test code as production code. 1.5 times as much is better.