Eclipse Indigo 中的 JUnit 测试没有报告任何内容?
我试图让 JUnit 4 测试在 Eclipse Indigo SR1 中正确运行,但有些事情很奇怪。在我能想到的最简单的情况下(如下所示):
package ints;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class IntTest {
@Before
public void setUp() throws Exception {
System.out.println("setUp()");
}
@Test
public void test() {
System.out.println("assertEquals(1, 1);");
assertEquals(1, 1);
}
@Test
public void test2() {
System.out.println("assertEquals(1, 2);");
assertEquals(1, 2);
}
}
当我在 Eclipse 中运行它时(Alt+Shift+X,T),JUnit 视图报告“运行:0/0,错误:0,失败:0”,而控制台显示以下内容,但我没有得到任何其他内容。我可以从测试方法中抛出异常它们也不显示。
setUp()
assertEquals(1, 1);
setUp()
assertEquals(1, 2);
关于给出什么有什么想法吗?
I'm trying to get JUnit 4 tests to properly run in Eclipse Indigo SR1, but something is screwy. In the simplest case that I can think of (as below):
package ints;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class IntTest {
@Before
public void setUp() throws Exception {
System.out.println("setUp()");
}
@Test
public void test() {
System.out.println("assertEquals(1, 1);");
assertEquals(1, 1);
}
@Test
public void test2() {
System.out.println("assertEquals(1, 2);");
assertEquals(1, 2);
}
}
When I run this in Eclipse (Alt+Shift+X, T), the JUnit view reports "Runs: 0/0, Errors: 0, Failures: 0" while the console displays the below, but I'm not getting anything else. I can throw exceptions from the test methods & they aren't displayed either.
setUp()
assertEquals(1, 1);
setUp()
assertEquals(1, 2);
Any ideas as to what gives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为您的系统上同时安装了 JUnit 3 和 JUnit4,并且该项目导入了错误版本的 JUnit。这会导致各种奇怪的问题。
在您的情况下,代码似乎根本没有被视为测试,如果您使用的是 JUnit3,这是有意义的。
检查您的构建路径以查看您正在使用哪个 JUnit。
I think you have both JUnit 3 and JUnit4 installed on your system and the project imports the wrong version of JUnit. This will cause all sorts of weird problems.
In your case it seems the code isnt being treated as tests at all, which makes sense if you are using JUnit3.
Check your buildpath to see which JUnit you are using.
我在使用 JUnit 时也遇到了同样的问题。我对旧的 JDK 进行了更新,但问题仍然存在,因此我从计算机中完全删除了所有 JDK,并安装了最新的 jdk 6,Eclipse Indigo 神奇地开始正常工作。
也许不断更新的jdk 6没有正确升级...
I had the same problem with JUnit. I ran update on my good old JDK, but the problem remained, so I completely deleted all JDK-s from my machine and installed the newest jdk 6 and the Eclipse Indigo magically started to work properly.
Maybe the continuously updated jdk 6 is not correctly upgraded...
检查计算机上的(本地)防火墙规则。一年前我遇到了同样的问题,允许 Eclipse/Java 的本地连接解决了这个问题。 (我刚刚找到了关于此的注释。)
Check the (local) firewall rules on the machine. I bumped into the same issue one year ago and allowing local connections for Eclipse/Java solved the issue. (I've just found a note about this.)
由于某种原因,卸载 1.7 32 位 JDK 为我解决了这个问题。它似乎不在路上或任何我能弄清楚的地方。这感觉有点太像魔法了,但它确实有效。
我安装了 4 个 JDK(1.6 和 1.7、32 位和 64 位)。现在我有3个。
For some reason uninstalling the 1.7 32-bit JDK solved this problem for me. It didn't seem to be on the path or anything that I could figure out. It feels a little too much like magic, but it worked.
I had 4 JDKs installed (1.6 & 1.7, 32-bit & 64-bit). Now I have 3.
我也有同样的问题。 JUnit 启动但不工作且未完成并且没有给出任何异常。对我来说,检查防火墙 iptables 命令并添加运行:
JUnit 需要此权限才能运行 - 允许内部接口通信。
I had the same problem. JUnit start but not working and not finished and not give any exception. For me worked check firewall iptables command and add run:
JUnit need this permission to running - allow internal interface communication.