开发者

JUnit4 in Eclipse

I'm trying to run some JUnit test units in Eclipse 3.5, but with no luck at all.

JUnit3 works fine.

When I create the JUnit4 Test unit, Eclipse offers to add the JUnit library to the class-path. 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.

If I choose Edit, the combo says "JUnit 4", and just below "Current location: Not Found".

When I launch a JUnit4 test, I get an error saying and internal error occurred, 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开发者_运维百科.

I've tried re-creating my projects and creating a 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 eclipse's classpath, but still the same problem.

[Edit2]

I also added junit-dep-4.8.1.jar, since I'm not sure if these dependencies are necessary, but no change.


Right click on the project name .

Built Path--> Add Libraries

Select the appropriate library from the list (JUnit 4 in this instance) .


In my Eclipse installation JUnit 4 is provided, it's in 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

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

Select JUnit there, and you can add and edit JARs.


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.
Another Debian PC presented the same issue. A clean download from eclipse.org solved the problem.

I will report this bug at some point :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜