The Art of Writing Software

TestUtil: Package for Unit Testing Setters/Getters

Series [ Unit Testing Setters and Getters ] Tags [ Java, JUnit, TestUtil, unit test ]

In a comment on an earlier post, a reader Tatsu reported on the TestUtil package from the GTC Group that’s a step ahead of us in this discussion. Here’s a sample snippet of all you have to do to test the setters/getters of a Java class:

public void testSettersAndGetters() {
  assertTrue(TestUtil.verifyMutable(underTest, 1, 0));

where underTest is the instance of the class you are testing (created and injected in the setUp method of your JUnit). If someone has time, please dig in and let’s understand what the 1 and 0 arguments are, and whether this is covering all the cases we’ve been talking about.