10

In eclipse:

  1. Window --> Preferences
  2. Expand Java at left side of panel --> JUnit is there under Java

How can I know the version of JUnit in eclipse?

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176

7 Answers7

24

You can use this code:

import junit.runner.Version;

System.out.println("JUnit version is: " + Version.id());
fortytwo
  • 580
  • 4
  • 9
  • Might be useful to mention that in order to add the JUnit libraries which come with Eclipse, just create a test class ( File -> New -> JUnit Test Case ), then Eclipse will ask you to choose and add JUnit libraries. – Ahmet Çavdar Sep 17 '20 at 13:40
7

If you selected JUnit4 over JUnit3, the version that Eclipse uses is the one in eclipse/plugins/org.junit_XXXX. For Eclipse Luna, it is eclipse/plugins/org.junit_4.11.0.v201303080030. Note that if you want to change it, based on all the things I tried, you can replace the junit.jar contained inside with the version you want.

Raul Santelices
  • 1,030
  • 11
  • 17
  • Agreed. This answer is the most straight-forward. Just go into the directory `eclipse/plugins/` and look for the JUnit jar file. The file will have the version number in the name. – stackoverflowuser2010 May 01 '16 at 20:00
2

Go to the project properties --> java build path --> in libraries tab you will see the junit jar. see the version on it.

Rishikesh Dhokare
  • 3,559
  • 23
  • 34
  • 1
    The default junit with eclipse does not show on libraries. I didn't add any external jar for JUnit. So what to do to know the JUnit version in this case? – Ripon Al Wasim May 24 '13 at 07:40
  • @RiponAlWasim That is because in a new project JUnit libraries are not added. If you just create a new test class ( File -> New -> JUnit Test Case ) you will see JUnit libraries under libraries tab. – Ahmet Çavdar Sep 17 '20 at 13:40
  • Thank you Ahmet Cavdar – Ripon Al Wasim Sep 20 '20 at 14:21
1

If you are cloned existing maven project and you want to check on which version your tests will run then you can check Junit version in you pom.xml file.

If you print your junit version from code then it will print from your maven repository i.e. the version present in your pom.xml

import junit.runner.Version;
System.out.println("Version="+Version.id()); 
Datta
  • 169
  • 1
  • 1
  • 10
0

what ever junit jar you might have upload to build path in eclipse will be the version of junit.

NPKR
  • 5,368
  • 4
  • 31
  • 48
  • This is the first time I have opened eclipse and I did not upload any junit version. The junit is default. How can I know the version of default junit provided with eclipse? – Ripon Al Wasim May 24 '13 at 07:35
0
version of junit.jar will tell u the version of your JUNIT in eclipse. I think it may be 
hidden in that jar
Ravi Dutt
  • 135
  • 2
  • 4
  • 16
-3

This morning I tried to run one of my test and I faced this issue.

The best solution I found which fixed my issue is this :

Select your spring boot project name in Package Explorer Right Click Select Maven Update Project

enter link description here

haider
  • 1
  • 1