JUnit 4 with Eclipse-jdt
FedoraForum.org - Fedora Support Forums and Community
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2010
    Location
    Italy
    Age
    33
    Posts
    80

    Thumbs up JUnit 4 with Eclipse-jdt [solved]

    Hello,
    I'm sorry, as I'm not sure if this is the right forum: this is a problem I'm having with software, it's on a x86_64 machine, but it's programming related (and I suspect it's a my problem not a fedora's problem as I can't find solutions)

    I'm using Eclipse since a month or two, and only today I wanted to learn how to use JUnit. I tried following some tutorials, but eclipse complains.
    Actually, it seems that Eclipse can't find JUnit4 (which is installed btw), as

    Project > Properties > Java Build Path > Libraries tab
    There is JUnit4, but editing it
    JUnit library version: JUnit 4
    Current Location: Not Found
    Source Location: Not Found

    But JUnit 3 have a valid
    Current Location: junit.jar - /usr/lib64/eclipse/dropins/jdt/plugins

    I tried adding by hand the system-installed junit4.jar file, but eclipse complains when running tests (a NullPointerException is thrown on launching).

    I'm actually using JUnit3, which works, but seems quite limited...

    What shall I do? How do I check that all the configuration is fine? Eclipse is so vast...

    Thanks
    ~Aki
    Last edited by akiross; 24th February 2010 at 02:25 PM.

  2. #2
    Join Date
    Sep 2008
    Location
    California
    Posts
    235
    Hey, Aki.

    This bug was fixed in version 3.5.1-22 of Fedora eclipse. Apparently, it was Fedora’s fault
    Have you updated Eclipse? Try that.

    If the error persists, a temporary workaround would be to add an Eclipse Library (in preferences→Java→Build Path→User Libraries) and specify the path to the JUnit4 in the Fedora repos (run: locate junit4).

  3. #3
    Join Date
    Feb 2010
    Location
    Italy
    Age
    33
    Posts
    80
    I'm using eclipse-jdt
    Version : 3.5.1
    Release : 22.fc12

    But the problem persists :\ I tried going into preferences→Java→Build Path→User Libraries, adding a library "junit4" and importing the /usr/share/java/junit4.jar
    But I don't know if this is sufficient - or if I did it wrong - as eclipse still complains:
    the import org.junit cannot be resolved

    Shall I configure something else and tell somehow eclipse to use that library for junit testing?

    Anyway thanks!

  4. #4
    Join Date
    Sep 2008
    Location
    California
    Posts
    235
    Hey, akiross.

    After creating the User Library in the Preferences menu, you need to configure your project to use it. Right‐click your project in the Package Explorer and choose Build Path→Add Libraries→User Library. Did you already do this?
    Build Path→Add Libraries→External Archives should also work.

    If that doesn’t work…
    Sometimes Eclipse does strange things with the .classpath file (in your project’s directory). You can try making a new Eclipse project, then copying over your project source and re‐adding the JUnit library.

  5. #5
    Join Date
    Feb 2010
    Location
    Italy
    Age
    33
    Posts
    80
    Thanks for these instructions, but still doesn't work:
    the imports are OK, as the annotations are recognized and no errors on the import org.junit, but when i Run As > JUnit Test, it gives an error:

    'Launching TestParser' has encountered a problem.
    An internal error occurred during: "Launching TestParser"
    Details>>
    An internal error occurred during: "Launching TestParser"
    java.lang.NullPointerException

    This is not my code fault (I guess), as even an empty test case gives this error when launching.

    Thanks again

    EDIT: With "empty test case" i mean a code like:

    Code:
    import org.junit.Test;
    public class TestSomething {
    	@Test
    	public void test() { }
    }
    EDIT2: Sorry, but I really can't find other infos apart that message... It doesn't give the backtrace in the Problems View :\
    Last edited by akiross; 22nd February 2010 at 01:04 PM.

  6. #6
    Join Date
    Jan 2010
    Posts
    10

    Possible resolution

    Can you try installing eclipse-pde and check whether the problem is still there?

  7. #7
    Join Date
    Feb 2010
    Location
    Italy
    Age
    33
    Posts
    80
    It solves!
    Thanks akurtakov!

  8. #8
    Join Date
    Oct 2007
    Posts
    22

    Re: JUnit 4 with Eclipse-jdt

    thx, also worked for me

    gregor

Similar Threads

  1. Eclipse
    By dnbwise in forum Using Fedora
    Replies: 1
    Last Post: 23rd December 2007, 12:13 AM
  2. Junit, PyDev, and Eclipse?
    By cypher543 in forum Using Fedora
    Replies: 3
    Last Post: 28th December 2006, 03:20 AM
  3. Junit and Java 5 to work in FC4
    By T.V.Casualty in forum Using Fedora
    Replies: 1
    Last Post: 19th October 2005, 11:25 PM
  4. Replies: 1
    Last Post: 16th June 2005, 11:12 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •