简体   繁体   English

Eclipse中的JUnit4

[英]JUnit4 in Eclipse

I'm trying to run some JUnit test units in eclipse 3.5, but with no luck at all. 我正试图在eclipse 3.5中运行一些JUnit测试单元,但根本没有运气。

JUnit3 works fine. JUnit3工作正常。

When I create the JUnit4 Test unit, eclipse offers to add the JUnit library to the class-path. 当我创建JUnit4测试单元时,eclipse提供将JUnit库添加到类路径中。 I accept, but when i check to see if it was added in the project's properties panel, I can see JUnit4 was added, but no JARS where included. 我接受了,但当我检查它是否已添加到项目的属性面板中时,我可以看到添加了JUnit4,但没有包含JARS。
If I choose edit, the combo says "JUnit 4", and just below "Current location: Not Found". 如果我选择编辑,组合会说“JUnit 4”,就在“当前位置:未找到”之下。

When I launch a JUnit4 test, I get an error saying and internal error occurred, NullPointerException. 当我启动JUnit4测试时,出现错误并发生内部错误,NullPointerException。

I've read for about two days now, and all references say eclipse INCLUDES JUnit4, but somehow, there seems to be something i'm missing. 我已经阅读了大约两天了,所有的引用都说eclipse包含JUnit4,但不知怎的,似乎有些东西我不见了。

I've tried re-creating my projects, and creating test in brand new ones with no luck. 我已经尝试重新创建我的项目,并在没有运气的情况下创建全新的测试。

package test;

import static org.junit.Assert.*;

import org.junit.Test;

public class AuthServiceTest {

    @Test
    public final void testValidateCredentials() {
        fail("Not yet implemented"); // TODO
    }

}

[Edit] I've added junit-4.8.1.jar to the project's classpath, and eclipe's classpath, but still the same problem. [编辑]我已经将junit-4.8.1.jar添加到项目的类路径和eclipe的类路径中,但仍然是同样的问题。 [Edit2] I also added junit-dep-4.8.1.jar, since i'm not sure if these dependencies are necessary, but no change. [Edit2]我还添加了junit-dep-4.8.1.jar,因为我不确定这些依赖项是否必要,但没有变化。

Right click on the project name . 右键单击项目名称。

Built Path--> Add Libraries

Select the appropriate library from the list (JUnit 4 in this instance) . 从列表中选择适当的库(本例中为JUnit 4)。

In my Eclipse installation JUnit 4 is provided, it's in plugins\\org.junit4_4.3.1\\junit.jar 在我的Eclipse安装中提供了JUnit 4,它位于plugins \\ org.junit4_4.3.1 \\ junit.jar中

If you can't find it, then I guess that you may need to download it. 如果你找不到它,那么我想你可能需要下载它。

You can associate your JUnit with the Eclipse JUnit settings in 您可以将JUnit与Eclipse JUnit设置相关联

Windows->Preferences->Java->Build Path->User Libraries

Select JUnit there, and you can add and edit JARs. 在那里选择JUnit,您可以添加和编辑JAR。

It appears that the Eclipse 3.5 from Fedora's repository doesn't include JUnit, and installing the appropriate package didn't include it either. 似乎Fedora的存储库中的Eclipse 3.5不包含JUnit,并且安装相应的包也没有包含它。
Another Debian PC presented the same issue. 另一个Debian PC提出了同样的问题。 A clean download from eclipse.org solved the problem. 从eclipse.org下载干净的解决了这个问题。

I will report this bug at some point :) 在某个时候报告这个bug :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM