For homework and projects, it may be useful to compare actual and expected output side-by-side. Eclipse has a nice comparison view that will align the different outputs and highlight the differences, even differences in whitespaces that may be otherwise difficult to see.

TABLE OF CONTENTS


Opening Compare Text View

Eclipse screenshot of the “Result Comparison” dialog for JUnit tests.

Eclipse screenshot of the “Result Comparison” dialog for JUnit tests.

Some of the tests compare text that can be opened in a side-by-side comparison view for debugging. To open this view, follow these steps:

  1. Open the JUnit view and run one or more tests.
  2. Click on a specific failing test; one that has a blue x icon. Tests with a x red icon threw an exception, and thus there is nothing to compare.
  3. In the “Failure Trace” section for that test, click the icon that looks like two connected window icons.

This will open up a comparison view. See below for how to use that view.

Opening Compare Files View

Animated GIF illustrating how to open the “Compare With” view in Eclipse.

Animated GIF illustrating how to open the “Compare With” view in Eclipse.

Some of the tests compare files instead of the difference between text output. To open a comparison view for two files, follow these steps:

  1. Control + Click or Command + Click the two files you want to compare so that they are both highlighted in the Project Explorer view.
  2. Right-click one of the selected files. This should open up a menu.
  3. Select “Compare With” from the menu.
  4. Select “Each Other” from the sub-menu.

Using the Comparison View