How to select or change JUnit version in Eclipse?
Asked Answered
C

3

13

Basically the source code I am using requires a very specific JUnit test version such as:

lucene-test-framework-XX.jar
  The compiled Lucene test-framework library.
  Depends on junit 4.10.x (not 4.9.x, not 4.11.x), and Apache Ant 1.7.x (not 1.6.x, not 1.8.x)

However, I am new to Eclipse, where and how do I change the JUnit to 4.10.x?

Thanks a lot in advance!

Crab answered 28/5, 2012 at 3:51 Comment(0)
D
14

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)

Daw answered 28/5, 2012 at 4:6 Comment(1)
Is there a way to change this for the workspace, aka all (future) projects?Cwm
C
3

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).

Clemmieclemmons answered 10/9, 2014 at 16:13 Comment(0)
S
2

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.

Stapleton answered 1/5, 2015 at 17:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.