For those who like juggling multiple tasks, Eclipse provides a great opportunity. Take developer testing for example. JUnit comes standard out of the box and the agile developer can literally start practicing Test Driven Development (TDD) right off the bat. As individual developers increase the number and detail of unit tests the team may want to know how much of the code base is actually being tested. This is where test coverage comes into the picture.

The agile teams practicing Continuous Integration gain insight of their test coverage through tools such as CruiseControl and Cobertura. Since test coverage reports are generated as part of the CI cycle, the latter two provide an aggregate view of the test coverage of the entire code base. The reports, while open to the entire team, are mostly analyzed by the architects or project managers who would like to gain insight of the team’s coverage and trends.

Individual developers working with Eclipse can also gain the same insight into their test coverage without having to commit changes and wait for the CI server to complete the build. Coverlipse is an Eclipse plugin designed to measure the test coverage of Java code. It’s fully integrated into the Eclipse environment and allows the agile developer to see which parts of the code are actually tested. The ability to see test coverage immediately provides the shortest path to knowing what each developer’s individual test coverage is, even before a single line of code is committed to the repository.

Quick Tutorial

  1. Download and start Eclipse 3.2
  2. Navigate to Help | Software Updates | Find and Install
  3. Select Search for new features to install
  4. Add a new remote site Coverlipse and point it to http://coverlipse.sf.net/update/
  5. Finish the wizard and restart Eclipse
  6. Create a new Java project
  7. Add the following Java class:
    public class NumberComparator {
      public NumberComparator() {
        super();
      }
      public boolean isGreater(int pFirst, int pSecond) {
        if (pFirst > pSecond) {
          return true;
        }
        return false;
      }
    }
    
  8. Add the following JUnit test case:
    import junit.framework.TestCase;
    public class NumberComparatorTest extends TestCase {
      public void testIsGreater() {
        NumberComparator nComp = new NumberComparator();
        assertTrue(nComp.isGreater(5, 4));
      }
    }
  9. In the Package Explorer, right-click on NumberComparatorTest and select Run As | JUnit w/ Coverlipse
  10. Wait for the test to complete
  11. Open the NumberComparator class. You should see the Coverlipse markers as in the following picture:
    coverlipse001
  12. Notice the red mark on the left. This indicates that part of the method is not covered by the unit test.
  13. Add a second assert to the JUnit test case as follows:

    assertFalse(nComp.isGreater(5, 6));

  14. Rerun JUnit w/ Coverlipse
  15. Notice there are no red marks now as the entire code is covered