Get rid of import suggestion for junit.framework.Assert

When using JUnit for creating unit tests, I have always felt annoyed that Eclipse keeps on suggesting (or even auto-importing) junit.framework.Assert, which is actually a deprecated type but appears first in the list of import suggestions.

To disable this behavior, one has to change the so-called Access Rules for the JUnit library.

To do this:

  1. Right-click you project and select Build Path -> Configure…
  2. Switch to Libraries tab and locate the used junit.jar
  3. Select Access rules and press Edit.
  4. Add a new rule with the rule pattern junit/framework/Assert and set its access level to Forbidden.
  5. Make sure that the rule appears before the junit/framework/* rule, which permits any acccess.

Now, Eclipse should only provide for one import quick fix, when using Assert. Even “Organize Imports” (Ctrl+Shift+O) should automatically find the correct solution now.

Thanks to this Stackoverflow post for hinting me at this solution.