1

My lecturer required a ZIP file containing my project, which he will import into Eclipse on his machine. I cannot guarantee he has jUnit on his machine, but I used jUnit in my project.

If I simply export the project to a ZIP (File > Export > Archive File ...) will the ZIP include (my version of) jUnit? And if not, how can I include jUnit in the ZIP?

Edit: Tested the import of a ZIP file, generated as above, on a fresh installation of Eclipse, on a virtual machine, and jUnit was there. When inspecting the .class file of the project I saw that it provides a URL to jUnit. So I guess my question has become: Where does Eclipse import jUnit from? And will this work in any setup of Eclipse (i.e. OS, version of Eclipse)?

Rodrigo
  • 321
  • 2
  • 11
  • is it a maven project ? – Sravya Mar 13 '17 at 09:53
  • Nope, just a regular Java project (File > New > Java Project). – Rodrigo Mar 13 '17 at 16:00
  • The URL to junit in your .classPath must be the path of the jar file in your machine. This will be added when you import/add the junit archives to your project. I don't think eclipse is doing this import automatically. It is just referring from the path that you have given. Hence it won't work in your lecturer machine if you share only the project. You need to separately share the junit jar file as well – Sravya Mar 14 '17 at 07:01
  • Thanks but I don't have a jUnit JAR on my machine. This is the URL in the .classpath file: org.eclipse.jdt.junit.JUNIT_CONTAINER/4 . – Rodrigo Mar 14 '17 at 13:46
  • Basically in the class path entry, what i referred was when the kind is lib. In your case, the entry kind may be con. In that case the library files are available with eclipse itself. Please go through the below link. It might help you. http://stackoverflow.com/questions/16960054/whats-the-use-of-the-configuration-in-classpath-for-eclipse-project-org-eclip – Sravya Mar 14 '17 at 13:53
  • Ok. So, as @Christian said below, JUnit comes with Eclipse. Which also means that if this ZIP is imported into an Eclipse that doesn't have the version of JUnit I am using (4), the tests won't run. If you wish to summarize this into an answer, I'll accept it. – Rodrigo Mar 14 '17 at 14:06

2 Answers2

0

JUnit comes standard with the download of any version of Eclipse. To use it, a new .java file needs to be created (File > New > JUnit Test Case). Find your program package and then name your .java file (usually something similar to the class which is being tested)

Example:
Name: HelloWorldTest
Class under test: HelloWorld

If you ever find the JUnit library is corrupt or isn't working again, you can download the current version straight from the web site

smttsp
  • 4,011
  • 3
  • 33
  • 62
  • Thank you Christian. Your answer helped me realise that Eclipse already has JUnit, but @Sravya's answer gives more details. – Rodrigo Mar 15 '17 at 10:31
0

JUnit comes with eclipse itself. It is usually the latest version. If you want to use any other version of Junit then you have to manually import the libraries to your project.

Now coming to your question that if you archive the project and share it with your lecturer then the zip file will not have the Junit library but it gets imported from eclipse libraries when the project is built. Again it is a specific version of JUnit depending on which eclipse version you are using. Few more details are mentioned HERE

You can check the version of Junit that eclipse provides as mentioned HERE

Community
  • 1
  • 1
Sravya
  • 149
  • 5