Eclipse Static Import Code Completion

Many popular framework provide facilities requiring static imports in your code.
Other than with regular Types, the Eclipse Java Development Tools (JDT) code completion does not work out-of-the-box for statically imported methods.

For example, when writing JUnit Test Cases, you often need to write assert*() methods, matchers, or even fail() methods which must be statically improted. The same applies for the mock up framework Mockito and a lot others.

To enable code completion for those static imports, the Eclipse JDT tooling provides a configuration within the preferences, called Favorites.
You can find them in the workspace preferences following the path:
Window -> Preferences -> Java -> Editor -> Content Assist -> Favorites

Eclipse Code Assistent Favorites Preferences

Adding the following new types is a good set to start with for JUnit Tests:

  • org.junit.Assert
  • org.hamcrest.CoreMatchers

Leave a Comment