14

I've started working on a large project where the IntelliJ environment has already been set up. The environment includes JUnit, and I can successfully run unit tests. I've seen screens where I can specify the usage of JUnit 3 or JUnit 4, but how can I determine which specific JUnit is being used to run my tests, e.g., JUnit 4.11?

I have already tried "Open Module Settings". When I look at the "Dependencies" tab, I don't see anything relating to JUnit, although I can run JUnit tests.

kc2001
  • 5,008
  • 4
  • 51
  • 92

2 Answers2

4

If you are looking for the JUnit libraries that are shipped with IntelliJ have a look at the corresponding jars in the lib/ directory of your Intellij IDEA installation.

For more information on this have a look at the online documention:

datentyp
  • 1,371
  • 12
  • 9
  • I've looked at those pages, and I've looked at the module dependencies in IDEA. For some reason, I am not seeing anything to do with JUnit, although I can run JUnit tests. I am editing my question to be more explicit. – kc2001 Feb 07 '13 at 14:17
  • 1
    @kc2001 - when you run JUnit tests in IntelliJ, you can see the java parameters in the first line of the console output. In this line there's a classpath reference to JUnit (..JetBrains\IntelliJ IDEA 12.0.3\plugins\junit\lib\junit-rt.jar in my case). It was added by Intellij and is unrelated to module dependencies. – Vic Feb 10 '13 at 11:08
  • @Vic Thanks for that. I feel so ignorant. Now that I know where junit-rt.jar is, how do I determine the version of it? – kc2001 Feb 12 '13 at 01:17
4

Which jar is used?

When you run JUnit from IntelliJ, the very first line of the console output displays your classpath. You can use Ctrl+F to find any "junit" references.

junit-rt.jar is a helper library that JetBrains might have written. By opening the jar as an archive with 7-zip, you will find that the only package inside it is under com.intellij

According to Java: Which of multiple resources on classpath JVM takes? the first reference to junit.jar is the one you will use.


What version is that jar?

Once you know which jar is being used, there are a number of ways to find the version. One is to use this code taken from https://stackoverflow.com/a/16729507/1405720

import junit.runner.Version;

System.out.println("JUnit version is: " + Version.id());

Another method might be to open up the jar as an archive and see if you can figure it out from there.

Community
  • 1
  • 1
mejdev
  • 3,509
  • 4
  • 24
  • 38