Close Window

Show Source |    | About   «  2.10. Writing JUnit Tests   ::   Contents   ::   2.12. Mutation Coverage In JUnit  »

2.11. Code Coverage In JUnit

2.11.1. Code Coverage In JUnit

One of the most useful features that the webcat grading system provides is information of total code coverage. Thankfully Eclipse has a couple of plugins that offer similar functionality so when you write your code you will not be dependent on webcat solely.

Step 1: Open Eclipse and select Help->Install New Software Step 2: A new window will appear similar to the following figure select the Add button.

Add New Software Window

Step 3: A pop up will appear asking for a name/location, enter NAME: Eclemma, and LOCATION:

Step 4: After providing the information, you will be redirected to a screen with the option to select EclEmma for installation. Click the checkbox and progress through the installation screens. Using EclEmma

After installing the plugin begin writing test code. After completion of the test code select the button selected in red in the below image.


Once the test have finished running the source code that was tested will now be high-lighted in three different colors. Green means that this line of code has been executed by the tests and are “covered.” Yellow indicates a segment of code that has multiple branches and that not all the branches in code have been reached (i.e. an if statement). Red indicates that this line of code has not been reached at all and as such is not covered.


Use these visuals to help determine what the test code is missing and how to improve the code coverage. In addition to showing the code missed by test cases EclEmma can also provide information regarding the total coverage of the entire project, the entire class, and each method in the class. In order to see this information select Window->Show View->Other and then Java->Coverage. A window similar to below will appear providing information.

Code coverage of the entire project

Figure 2.11.4: Code Coverage For Each Class In The Eclipse Project

Code coverage of each method in the BST class

Figure 2.11.5: Code Coverage Of Each Method In The BST Class

   «  2.10. Writing JUnit Tests   ::   Contents   ::   2.12. Mutation Coverage In JUnit  »

Close Window