如何为Eclipse插件项目设置测试项目

时间:2023-01-13 12:31:15

I'm working on a eclipse plug-in and I've tried to create another test project seperate from the plug-in. The reason I do this is to not let the plug-in depend on jUnit when it is exported. However, I can't access the Eclipse Plug-in API when I do the testing. Whenever I try to add Plug-in dependencies the import list to that is empty.

我正在开发一个eclipse插件,我试图从插件中创建另一个测试项目。我这样做的原因是在导出插件时不要让插件依赖于jUnit。但是,在进行测试时,我无法访问Eclipse Plug-in API。每当我尝试添加插件依赖项时,导入列表都是空的。

Does anyone know how to import Eclipse plug-in API to an existing project? The workspace layout looks like this at the moment:

有谁知道如何将Eclipse插件API导入现有项目?工作区布局目前看起来像这样:

+- com.foo.myplugin
|     |
|     +- JRE System Library
|     |
|     +- Plug-in Dependencies
|     |
|     +- src
|     |
|     +- icons, META-INF, plugin.xml, etc...
|
+- com.foo.myplugin.test
      |
      +- JRE System Library
      |
      +- JUnit 4
      |
      +- src

3 个解决方案

#1


6  

The recomended way of ding this seems to be with Plug-in fragments:

推荐的方式似乎是插件片段:

http://rcpquickstart.com/2007/06/20/unit-testing-plug-ins-with-fragments/

The fragment gets a high-degree of access to your plugin's code and separates the testing logic / dependencies from the plugin itsself.

该片段可以高度访问您的插件代码,并将测试逻辑/依赖项与插件本身分开。

Now if only I could find a way to test them in an automated system... (see: Automating unit tests (junit) for Eclipse Plugin development )

现在,如果我能找到一种方法在自动化系统中测试它们...(参见:Eclipse插件开发的自动化单元测试(junit))

#2


3  

You can export the plug-in dependency from the plug-in project. Easiest way is like this:

您可以从插件项目中导出插件依赖项。最简单的方法是这样的:

  1. Go to your com.foo.plugin project properties

    转到com.foo.plugin项目属性

  2. Go to Java Build Path > Order and Export

    转到Java构建路径>订单和导出

  3. Check the Plug-in Dependencies entry

    检查Plug-in Dependencies条目

The test project should now be able to use plug-in API without the need to use all plugin configuration required for a plug-in project.

测试项目现在应该能够使用插件API,而无需使用插件项目所需的所有插件配置。

#3


0  

You could try to add the plugin nature to your new myplugin.test project.

您可以尝试将插件性质添加到新的myplugin.test项目中。

In your .project file:

在.project文件中:

<natures>

        <nature>org.eclipse.pde.PluginNature</nature>
        [...]
</natures>

Then in the .classpath, add:

然后在.classpath中添加:

<classpath>
        [...]
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
        [...]
</classpath>

Delete your myplugin.test from the workspace, re-import that project and see if that does the trick...

从工作区中删除myplugin.test,重新导入该项目,看看是否有诀窍......

#1


6  

The recomended way of ding this seems to be with Plug-in fragments:

推荐的方式似乎是插件片段:

http://rcpquickstart.com/2007/06/20/unit-testing-plug-ins-with-fragments/

The fragment gets a high-degree of access to your plugin's code and separates the testing logic / dependencies from the plugin itsself.

该片段可以高度访问您的插件代码,并将测试逻辑/依赖项与插件本身分开。

Now if only I could find a way to test them in an automated system... (see: Automating unit tests (junit) for Eclipse Plugin development )

现在,如果我能找到一种方法在自动化系统中测试它们...(参见:Eclipse插件开发的自动化单元测试(junit))

#2


3  

You can export the plug-in dependency from the plug-in project. Easiest way is like this:

您可以从插件项目中导出插件依赖项。最简单的方法是这样的:

  1. Go to your com.foo.plugin project properties

    转到com.foo.plugin项目属性

  2. Go to Java Build Path > Order and Export

    转到Java构建路径>订单和导出

  3. Check the Plug-in Dependencies entry

    检查Plug-in Dependencies条目

The test project should now be able to use plug-in API without the need to use all plugin configuration required for a plug-in project.

测试项目现在应该能够使用插件API,而无需使用插件项目所需的所有插件配置。

#3


0  

You could try to add the plugin nature to your new myplugin.test project.

您可以尝试将插件性质添加到新的myplugin.test项目中。

In your .project file:

在.project文件中:

<natures>

        <nature>org.eclipse.pde.PluginNature</nature>
        [...]
</natures>

Then in the .classpath, add:

然后在.classpath中添加:

<classpath>
        [...]
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
        [...]
</classpath>

Delete your myplugin.test from the workspace, re-import that project and see if that does the trick...

从工作区中删除myplugin.test,重新导入该项目,看看是否有诀窍......