On 3/18/2010 3:22 PM, Rhino wrote:
I think I understand the basics of using JUnit - I'm still using JUnit3
for the moment - but I want to ask some things that I don't find clear in
the documentation that I've found.
Would it be reasonable to say all of the following?
1. For each class that I develop, I should have one JUnit class that
extends TestCase and that this TestCase class should test each of the
methods in the class I developed?
Sort of, I'd say. Private and even package-private classes
might get a waiver, the idea being that their "contracts" are only
with the public classes that "employ" them. Non-public nested
classes, same thing: If they're really just "implementation details"
of their containing classes, they might not need separate testing.
(For some inner classes, it won't be possible to test in isolation.)
"Each method" may be a overkill, too. Getters and setters come
to mind as "too simple to test" -- usually.
I recommend testing them as well.
They are easy to test and weird things have been seen in code before.