CIT 594 Eclipse FAQ
Spring 2004, David Matuszek
  1. How do I get the assert statement to work?
  2. How do I get line numbers?
  3. How do I get soft tabs?
  4. How do I run javadoc?
  5. Why are my JUnit results not showing up?
  6. How do I create a test suite?
  7. In JUnit, what's the difference between a "failure" and an "error"?
  8. Why does Source->Format really mess up my formatting?

  1. How do I get the assert statement to work?

    Go to Window -> Preferences -> Java -> Compiler -> Compliance and Classfiles
    and set the Compiler Compliance Level to 1.4. This tells the compiler to recognize and allow assert statements, but does not enable them.
    In Eclipse 3, the settings are a little fussier. Go to Window -> Preferences -> Java -> Compiler -> Compliance and Classfiles and set:
    Compiler Compliance Level: to 1.4
    Use default compliance settings to unchecked
    Generated .class files compatibility: to 1.4
    Source compatibility: to 1.4
    Disallow identifiers called 'assert': to Error
    Compiler Compliance Level to 1.4
    To enable (make active) assert statements, you must set a flag to the compiler. Go to Run -> Run... -> Arguments, and in the box labeled VM arguments:, enter either -enableassertions or just -ea. Accept the changes and close the dialog.

    To get Javadoc to recognize the assert statement, see How do I run Javadoc?

  2. How do I get line numbers?

    Go to Window -> Preferences -> Editor -> Appearance and check Show line numbers

  3. How do I get soft tabs?

    To get soft tabs (tabs replaced by spaces) as you type, go to Window -> Preferences -> Java -> Editor -> Typing and uncheck Insert space for tabs (see Code Formatter preference page).

    To replace tabs by spaces when you reformat code, go to Window -> Preferences -> Java -> Code Formatter -> Style and uncheck Insert tabs for indentation, not spaces.

  4. How do I run javadoc?

    1. In the Package Explorer window, choose the package or file for which you want to generate documentation.
    2. Choose File -> Export... -> Javadoc -> Next>
    3. Select the project, and the destination for the javadoc files. Normally, you should only generate documentation for public fields and methods.
    4. If you have no assert statements, you can click Finish at this point.
    5. Click Next >
    6. Click Next >
    7. Check JRE 1.4 source compatibility (otherwise your assert statements will be treated as errors). [See also How do I get the assert statement to work?]
    8. Click Finish.

  5. Why are my JUnit results not showing up?

    Maybe it's because all your tests succeeded. For more satisfying results, go to Window -> Preferences -> Java -> JUnit and uncheck Show the JUnit results view only when an error or failure occurs.

  6. How do I create a test suite?

    Go to File -> New -> Other... -> Java -> JUnit -> TestSuite, and click Next>. Select all the classes, and click Finish.

    You can run this test suite the same way you run other JUnit tests.

  7. In JUnit, what's the difference between a "failure" and an "error"?

    A failure is when one of your assertions fails--that is, your program does something wrong, and your JUnit test notices and reports the fact. An error is when some other Exception occurs--one you haven't tested for and didn't expect, such as a NullPointerException or an ArrayIndexOutOfBoundsException.

  8. Why does Source->Format really mess up my formatting?

    You have unmatched brackets, braces, or parentheses, and the code reformatter is doing the best it can. Find the syntax error (somewhere near the beginning of the messed up formatting), fix it, and reformat.