Don't use junit.framework

Every once in a while I see somewhere a wrong import to the old, deprecated junit.framework instead of org.junit.

I particularly believe they should remove this package and put it in a junit-compat jar or something… but, while they don’t do that, we can avoid those old imports with 2 basic steps:

1. Replace all old imports with the new imports

This is pretty straightforward with a simple bash script:

for file in $(git grep --break --heading "import junit." | grep java); do
  sed -i.bak s/junit.framework/org.junit/g $file
  rm -rf $file.bak

2. Don’t accept it in new code

The second step is basically to break the build whenever someone try to use those old imports. A simple way to do that is using the restrict-maven-plugin.

An example of configuration for maven will look like this:

      <restriction>com.carlosbecker.* to junit.*</restriction>

Sure it is a simple issue, which might never cause you problems, but, if one day the Junit team remove the old packages (probably soon), you will have a headache. Besides that, writing new code using deprecated classes?

Related Posts

Fast and easy Go binaries delivery


Fixing alerts