如何判断JUnit IntelliJ的哪个特定版本正在使用? [英] How can I tell which specific version of JUnit IntelliJ is using?
问题描述
我已经开始研究已经设置了IntelliJ环境的大型项目。环境包括JUnit,我可以成功运行单元测试。我已经看过屏幕,我可以指定JUnit 3或JUnit 4的用法,但是如何确定使用哪个特定的JUnit来运行我的测试,例如JUnit 4.11?
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?
我已经尝试过打开模块设置。当我查看Dependencies选项卡时,我没有看到任何与JUnit有关的内容,尽管我可以运行JUnit测试。
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.
推荐答案
使用哪个jar?
当您从IntelliJ运行JUnit时,控制台输出的第一行显示您的类路径。您可以使用Ctrl + F查找任何junit引用。
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是JetBrains可能编写的帮助程序库。通过使用7-zip打开jar作为存档,您会发现其中唯一的包是在com.intellij
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
根据Java:类路径JVM中的多个资源中的哪一个需要?对junit的第一个引用。 jar是你将要使用的。
According to Java: Which of multiple resources on classpath JVM takes? the first reference to junit.jar is the one you will use.
那个罐子的版本是什么?
一旦知道正在使用哪个jar,就有很多方法可以找到该版本。一种是使用此代码取自 https://stackoverflow.com/a/16729507/1405720
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());
另一种方法可能是打开jar作为档案,看看你是否可以从中找出它那里。
Another method might be to open up the jar as an archive and see if you can figure it out from there.
这篇关于如何判断JUnit IntelliJ的哪个特定版本正在使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!