views:

1927

answers:

2

I am using Eclipse Galileo for Java EE, and I want to configure JUnit to show me the source code when I try to navigate to its methods. I've tried attaching source to the JUnit library, but the library definition is not editable. I cannot even find where to configure the JUnit library in the preferences.

When I open the Add Library window and choose JUnit, I see a dialog where I can choose the JUnit version, but it shows that Source Location is "not found".

How can I configure Eclipse to find JUnit's source?

+1  A: 

As mentioned in this thread, if you have downloaded the SDK version of Galileo, yu have the sources of the main plugins.

For JUnit, this would be:

 <pathTo>\eclipse-SDK-3.5-win32-x86_64\eclipse\plugins\org.junit4.source_4.5.0.v20090423.jar

You can try to add that as a source file in the Source tab of a JUnit launcher configuration and see if that solves your issue when you are debugging your JUnit test and are stepping through JUnit native methods.

(Note: I have the x64 version of eclipse Galileo, but I believe the file is the same for the x32 or for other platforms)

VonC
Thanks for the reply, but I don't have the Eclipse SDK. However, I have found a way to do it without downloading the whole SDK. Please check my solution.
Hosam Aly
+2  A: 

I downloaded the Eclipse SDK and checked the differences, and I finally got it to work.

  1. Download this JAR into your eclipse/plugins directory.

  2. Edit the file source.info in your eclipse/configuration/org.eclipse.equinox.source directory, and add the following line:

    org.junit4.source,4.5.0.v20090423,plugins/org.junit4.source_4.5.0.v20090423.jar,-1,false

  3. Open the file artifacts.xml in your eclipse directory, and add the following fragment:

    <artifact classifier='osgi.bundle' id='org.junit4.source' version='4.5.0.v20090423'>
      <properties size='2'>
        <property name='artifact.size' value='128389'/>
        <property name='download.size' value='128389'/>
      </properties>
    </artifact>
    
  4. If Eclipse is already open, you'll need to restart it for the changes to be detected.

Note: For Eclipse 3.6 (Helios), you should use the updated JAR(s). See the comments by @Stunningfire and @Milo.

Hosam Aly
Thank you for this feedback, very interesting. +1
VonC
You could select your own answer as the official one if you want (no reputation gain in this gain, though)
VonC
Nice answer. Can you update it for the Helios/3.6 release?
Suppressingfire
I believe the new URL is ftp://ftp.osuosl.org/pub/eclipse/eclipse/updates/3.6/R-3.6-201006080911/plugins/org.junit.source_4.8.1.v4_8_1_v20100427-1100.jar and the version would presumably be 4.8.1.v4_8_1_v20100427-1100
Suppressingfire
I haven't downloaded Eclipse 3.6 yet, so I just referenced your comment for now. I might update it later if I have time.
Hosam Aly
Just want to confirm that this solution works on 3.6 service release 1. I don't know whether it was necessary, but I also added the the jar for 3.8.2 source code, as I use Junit 3 launcher. Used the following two jars:ftp://ftp.osuosl.org/pub/eclipse/eclipse/updates/3.6/R-3.6.1-201009090800/plugins/org.junit.source_3.8.2.v3_8_2_v20100427-1100.jarftp://ftp.osuosl.org/pub/eclipse/eclipse/updates/3.6/R-3.6.1-201009090800/plugins/org.junit.source_4.8.1.v4_8_1_v20100427-1100.jar
Milo