简体   繁体   English

如何在Eclipse中配置JUnit的Source?

[英]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. 我正在使用Eclipse Galileo for Java EE ,我想配置JUnit以在我尝试导航到它的方法时向我展示源代码。 I've tried attaching source to the JUnit library, but the library definition is not editable. 我已尝试将源附加到JUnit库,但库定义不可编辑。 I cannot even find where to configure the JUnit library in the preferences. 我甚至无法在首选项中找到配置JUnit库的位置。

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". 当我打开Add Library窗口并选择JUnit时,我看到一个对话框,我可以在其中选择JUnit版本,但它显示源位置“未找到”。

How can I configure Eclipse to find JUnit's source? 如何配置Eclipse以查找JUnit的源代码?

I downloaded the Eclipse SDK and checked the differences, and I finally got it to work. 我下载了Eclipse SDK并检查了差异,我终于开始工作了。

  1. Download this JAR into your eclipse/plugins directory. 将此JAR下载到您的eclipse/plugins目录中。

  2. Edit the file source.info in your eclipse/configuration/org.eclipse.equinox.source directory, and add the following line: 编辑eclipse/configuration/org.eclipse.equinox.source目录中的文件source.info ,并添加以下行:

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

  3. Open the file artifacts.xml in your eclipse directory, and add the following fragment: eclipse目录中打开文件artifacts.xml ,并添加以下片段:

     <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. 如果Eclipse已经打开,则需要重新启动它才能检测到更改。

Note: For Eclipse 3.6 (Helios), you should use the updated JAR(s). 注意:对于Eclipse 3.6(Helios),您应该使用更新的JAR。 See the comments by @Supressingfire and @Milo. 请参阅@Supressingfire和@Milo的评论。

Note: on Eclipse 3.6(Helios), step 3 (artifacts.xml) is not necessary. 注意:在Eclipse 3.6(Helios)上,不需要步骤3(artifacts.xml)。
Tested on Ubuntu Eclipse 3.6: 在Ubuntu Eclipse 3.6上测试:
Version: Helios Service Release 2 版本:Helios Service Release 2
Build id: 20110218-0911 构建ID:20110218-0911

As mentioned in this thread , if you have downloaded the SDK version of Galileo, you have the sources of the main plugins. 本主题所述 ,如果您下载了Galileo的SDK版本,则可以获得主要插件的来源。

For JUnit, this would be: 对于JUnit,这将是:

 <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. 您可以尝试将其作为源文件添加到JUnit启动程序配置的“源”选项卡中,并查看在调试JUnit测试时是否解决了您的问题并且正在逐步执行JUnit本机方法。

(Note: I have the x64 version of eclipse Galileo, but I believe the file is the same for the x32 or for other platforms) (注意:我有eclipse Galileo的x64版本,但我相信x32或其他平台的文件是相同的)

@Hosam Aly answer also works in Eclipse 4.3.1: @Hosam Aly的答案也适用于Eclipse 4.3.1:

  1. The jar to download is here 要下载的jar就在这里
  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 附加到eclipse\\configuration\\org.eclipse.equinox.source的文本是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 我不需要更改artifacts.xml

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. 我的eclipse版本是4.6.0,到目前为止我唯一能解决的解决方案是从ftp://ftp.osuosl.org/pub/下载名为org.junit.source_4.12.0.v201504281640.jar的源文件。 eclipse / eclipse / updates / 4.6 / R-4.6-201606061100 / plugins / ,然后把它放到eclipse \\ plugins中,然后重启eclipse然后源文件自动绑定到适当的junit jar文件。

最后结果

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

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