Configuring the JUnit test runner for code coverage on Java projects

To make JUnit results available in the code coverage results view, configure a JUnit 4 with Enhanced Code Coverage test runner.

Procedure

  1. Enable code coverage on your project. Right-click your project and select Properties > Code Coverage. Select Enable code coverage. Click OK.
    Enable code coverage
  2. Create a JUnit launch configuration. Right-click the class that runs your tests. Select Properties > Run/Debug Settings. Click New, select JUnit, and click OK.
    Create a new configuration
    The edit configuration dialog opens.
  3. Set the test runner. In the Test runner section of the edit configuration dialog, select JUnit 4 with Enhanced Code Coverage. Click OK.
    Set test runner
    Note: For the Test runner you can also choose JUnit 3 or JUnit 4. In these cases, results will be displayed under Java Code Coverage Workspace Results in the results view. With JUnit 3 and JUnit 4 you will only get code coverage result for the whole test suite, not individual test cases. With JUnit 4 with Enhanced Code Coverage you will see results under JUnit Code Coverage Workspace Results for each JUnit test case within a JUnit test suite.
  4. Run the JUnit.
    Run JUnit
  5. View the results. The results of the run are available in the Code Coverage Results view. If you do not see this view, select Window > Show View > Other > Code Coverage > Code Coverage Results.
    View results