By dwdyer
via blog.uncommons.org
Published: Apr 02 2008 / 15:48
A frequent topic of Java-related blogs is whether it is worthwhile to write unit tests for simple getters and setters. What bothers me most is the motivation for wanting to test getters and setters in the first place. It seems that many of those advocating unit testing simple getters and setters are driven by a desire to improve their coverage scores with the actual utility of the tests a secondary concern.
Comments
dzonelurker replied ago:
Ever heard of Java Beans? "Its properties must be accessible using get, set and other methods (so called accessor methods) following a standard naming convention. This allows easy automated inspection and updating of bean state by frameworks" http://en.wikipedia.org/wiki/JavaBeans
A lot of Java frameworks are built around JavaBeans. The question of "too many getters and setters" and "avoiding testing difficult code" is moot.
Voters For This Link (9)
Voters Against This Link (2)