如何配置 IntelliJ 以使用 JUnit 4 运行测试?
应该很简单,但我无法弄清楚。
在 IntelliJ 中运行单元测试时,我找不到一种方法来告诉 IntelliJ-9.0 它应该使用 JUnit4 而不是 JUnit3。
当测试失败时,IntelliJ 控制台显示:
MyTests.testConstraints(MyTests.groovy:20) 位于
...
com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:108) 在 com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:42) ...
你知道如何用 JUnit4 替换 JUnit3 吗?
Should be simple but I couldn't figure it out.
When running my unit test inside IntelliJ, I could not find a way to tell IntelliJ-9.0 that it should use JUnit4 instead of JUnit3.
When a test fails, IntelliJ console displays:
MyTests.testConstraints(MyTests.groovy:20) at
...
com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:108)
at
com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:42)
...
Do you know how to replace JUnit3 by JUnit4 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
'com.intellij.junit3' 包属于 IDEA 二进制文件,而不是 junit3 或 junit4。因此,问题本身本质上似乎是不正确的 - 如果 IDEA 代码库正确执行测试,则其内部使用的包名称没有区别。
'com.intellij.junit3' package belongs to IDEA binaries, not to junit3 or junit4. So, the question itself seems to be incorrect in essence - there is no difference in what package name is used by IDEA codebase internally if it correctly executes the tests.
听起来真正的问题可能是您正在尝试使用 junit 4 和低于 1.3 的 grails 版本。 Grails 1.2.x 及更低版本仅支持 Junit 3 测试。 Grails 1.3 最终将获得 junit 4 支持。 stackoverflow 链接文本对此进行了讨论
It sounds like the real problem may be that you are trying to use junit 4 with a grails version less than 1.3. Grails 1.2.x and lower only support Junit 3 tests. Grails 1.3 will finally have junit 4 support. This was discussed on stackoverflow link text
我在 10.5 内的 java 应用程序中遇到了同样的问题,结果是我的项目语言级别设置为 5.0,而不是 8.0。
要更改此设置,请转到文件->项目结构->项目->项目语言级别
并将其更改为所需的级别。不确定可以在哪个级别使用 JUnit4,但将其设置为 5.0 将使其使用 JUnit3。将其设置为 8.0 使其使用 JUnit4
I had the same problem with a java app inside 10.5, and it turned out to be my Project language level set to 5.0 as opposed to 8.0.
To change this go to File->Project Structure->Project->Project language level
And change this to the required level. Not sure at which level you can use JUnit4, but setting this to 5.0 will make it use JUnit3. Setting it to 8.0 makes it use JUnit4
您可以使用注释来注释您的测试类,以指示 junit 它将使用的运行程序
You can annotate your test class with an annotation to indicate junit the runner it will use
我找到了!
这样就完成了!
I found it!
And that's done !
我试图把:
放在测试的开头。
IntelliJ 对此有所抱怨,但要求“加载”JUnit4.class。
所以我删除了@RunWith(JUnit4.class)。
但“加载”似乎已经解决了问题 -
@Ignore
现在受到尊重!I tried to put:
at the beginning of a test.
IntelliJ complained about this, but asked to 'load' JUnit4.class.
So I deleted
@RunWith(JUnit4.class)
.But the 'loading' seems to have fixed the problem -
@Ignore
is now respected!将 JUnit 4 JAR 放入您的 CLASSPATH 中并查看 IntelliJ 是否选择它。
JUnit 插件似乎运行版本 3 或版本 4。
我敢打赌这与您编写 JUnit 测试的方式有关。贴一张来确认一下。如果您使用 JUnit 4 风格,我敢打赌 IntelliJ 会正确运行它。
Put the JUnit 4 JAR in your CLASSPATH and see if IntelliJ picks it up.
The JUnit plug-in appears to run either version 3 or 4.
I'll bet that it has to do with the way you're writing your JUnit tests. Post one to confirm. If you use the JUnit 4 style, I'll bet IntelliJ would run it properly.