Eclipse Indigo 中的 JUnit 测试没有报告任何内容?

发布于 2024-12-10 10:13:17 字数 791 浏览 0 评论 0原文

我试图让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

南街女流氓 2024-12-17 10:13:17

我认为您的系统上同时安装了 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.

贪了杯 2024-12-17 10:13:17

我在使用 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...

临风闻羌笛 2024-12-17 10:13:17

检查计算机上的(本地)防火墙规则。一年前我遇到了同样的问题,允许 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.)

怀里藏娇 2024-12-17 10:13:17

由于某种原因,卸载 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.

躲猫猫 2024-12-17 10:13:17

我也有同样的问题。 JUnit 启动但不工作且未完成并且没有给出任何异常。对我来说,检查防火墙 iptables 命令并添加运行:

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

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:

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

JUnit need this permission to running - allow internal interface communication.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文