How to select or change JUnit version in Eclipse?

The problem, at least in Eclipse Luna SR1/SR2, is that Eclipse seems to prioritize the packaged plugin with JUnit 4.11 in "eclipse/plugins/org.junit_4.11.0.v201303080030". Even after trying the answer above to force the version I needed, I kept getting the same test errors so it seems that Junit 4.11 was still being used.

The only solution that has worked so far for me is to replace the junit.jar in that directory (eclipse/plugins/org.junit_4.11.0.v201303080030) with the version I wanted.


Although the question is how to use a very particular version, the title of the question would also be valid for switching just between JUnit3 and JUnit4. This answer says how to do this.

Since quite a long time the junit library is part of the eclipse distribution. In eclipse Kepler one can switch between JUnit3 and JUnit4, both covered by the effective JUnit Release 4.11.0 (because JUnit3 is still compatible with JUnit4).

Right click on your project, select BuildPath/ConfigureBuildPath and select the tab Libraries. Let's suppose there is the library JUnit3 listed and you want to switch to JUnit4. Select the entry JUnit3, then the button "Remove", then "Add library". In the following wizard you choose "JUnit", "next", "JUnit4" in the dropdown and "Finish".

Maybe you have noticed in the ProjectExplorer that the JUnit4-Library - in contrast to JUnit3 - includes also the hamcrest-core library (which provides powerful matchers).


I have changed mine out in the past by (specifically) removing the prior, then adding the specific JUnit (External) JAR in my project properties' library settings. The steps are as below:

  1. Project > Properties > Java Build Path > Libraries
  2. Click "Add External JARs..." button at right side --> Select your preferred JUnit jar
  3. Click OK button


(source: aggroculture.com)