Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure JUnit's Source in Eclipse?

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?

like image 425
Hosam Aly Avatar asked Jul 05 '09 14:07

Hosam Aly


People also ask

How do I import junit4 into eclipse?

Open eclipse → right click on project and click on property > Build Path > Configure Build Path and add the junit-4.10. jar in the libraries using the button Add External Jar.

How do I add JUnit Jupiter to eclipse?

#1) Create a new Project folder. #2) Right-click on the project folder created, and click on Build Path => Configure build path. #3) A window titled Java Build Path opens. #4) Click on the External Jars button which opens up a window that allows you to browse the JUnit jar files or library files.


4 Answers

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 @Supressingfire and @Milo.

Note: on Eclipse 3.6(Helios), step 3 (artifacts.xml) is not necessary.
Tested on Ubuntu Eclipse 3.6:
Version: Helios Service Release 2
Build id: 20110218-0911

like image 65
Hosam Aly Avatar answered Oct 09 '22 04:10

Hosam Aly


My eclipse version is 4.6.0, the only solution that has worked so far for me is to download the source file which named org.junit.source_4.12.0.v201504281640.jar from ftp://ftp.osuosl.org/pub/eclipse/eclipse/updates/4.6/R-4.6-201606061100/plugins/, then placed it into eclipse\plugins, afterwards restart eclipse then the source file has bound to the appropiate junit jar file automatically.

final result

like image 36
黄东辉 Avatar answered Oct 09 '22 03:10

黄东辉


As mentioned in this thread, if you have downloaded the SDK version of Galileo, you 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)

like image 35
VonC Avatar answered Oct 09 '22 02:10

VonC


@Hosam Aly answer also works in Eclipse 4.3.1:

  1. The jar to download is here
  2. The text to append to eclipse\configuration\org.eclipse.equinox.source is org.junit.source,4.11.0.v201303080030,plugins/org.junit.source_4.11.0.v201303080030.jar,-1,false
  3. I did not need to change artifacts.xml
like image 20
Konstantin Tarashchanskiy Avatar answered Oct 09 '22 03:10

Konstantin Tarashchanskiy