How to select or change JUnit version in Eclipse?

2019-01-27 17:25发布

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!

3条回答
神经病院院长
2楼-- · 2019-01-27 18:06

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

http://aggroculture.com/images/JUnitChange.png

查看更多
相关推荐>>
3楼-- · 2019-01-27 18:08

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.

查看更多
Evening l夕情丶
4楼-- · 2019-01-27 18:13

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

查看更多
登录 后发表回答