Hi, I found this example in the book
JUnit In Action (2nd ed). The first 3 code snippets are from the book. Note: none of these extend any special classes or implement any special interfaces (ie. Spring controllers,
Struts), and some of the code has been left out for brevity's sake.
The question I have is how the
unit test should be written. In the above unit test, he is calling both the addHandler(...) and getHandler(...) methods from within the same test. Now, as a general rule of thumb, shouldn't he be testing out only the addHandler(...) method if he's testing the adding functionality? Doesn't this particular unit test incorrectly assume that getHandler() works correctly? Imagine if a unit test called, say, 5 different methods on an object. If the test fails, you don't know if the problem is coming from method1 or method2 or method3, etc. I mean if I were asked to come up with a unit test that tested addHandler(), mine would look like:
Is my assessment totally off base? :P