使用随附的工作区项目运行Eclipse插件测试 [英] Run Eclipse Plug-in Test with included workspace projects
问题描述
我正在编写一个小型Eclipse插件并为此进行一些测试.我通过指定插件在Headless Mode
中运行来启动插件测试.我想在那些测试中访问工作空间中的活动Java项目,但是当我执行它们时,工作空间为空.我使用以下代码来获取所有Java项目(效果很好):
I'm writing a small Eclipse plug-in and some tests for it. I'm starting the plug-in tests by specifying them to run in Headless Mode
. I want to access the active Java projects within the workspace in those tests, but when I execute them, the workspace is empty. I use the following code to get all Java projects (which works fine):
IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
for(IProject project : myWorkspaceRoot.getProjects()) {
if(project.isOpen() && isJavaProject(project)) {
IJavaProject javaProject = JavaCore.create(project);
projects.put(project.getName(), javaProject);
}
}
但是,项目始终为空.这是因为Headless Mode
我猜想使用空工作空间启动了一个新的Eclipse实例.我的问题是:我可以以某种方式指定测试应该在当前的Eclipse实例中运行,还是可以指定想要在新创建的工作空间中拥有的项目?
However, the projects are always empty. This is due to the fact that the Headless Mode
starts a new Eclipse instance with an empty workspace I guess. My question is: can I somehow either specify that the tests should run in the current Eclipse instance OR can I specify the projects I want to have in the newly created workspace?
推荐答案
我想出一种简单的方法来设置测试workspace
,并希望与您共享(即使这意味着回答我自己的问题):>
I figured out an easy way to setup a test workspace
and wanted to share it with you (even though this means answering my own question):
- 打开
Eclipse
并在光盘上的某个地方创建一个新的workspace
- 将一些示例项目添加到新的
workspace
- 打开一个包含
Plug-in Test
代码的Eclipse
实例 - 在
JUnit Plug-in Test Launch Configuration
中,转到Main
选项卡
- Open
Eclipse
and create a newworkspace
somewhere on the disc - Add some sample projects to the new
workspace
- Open an
Eclipse
instance which holds thePlug-in Test
code - In the
JUnit Plug-in Test Launch Configuration
, go to theMain
tab
- 指定在 1)中创建并在 2) 中填充的
- 运行测试,测试将从指定的
workspace
及其中的所有项目开始
workspace
- Specify the
workspace
created in 1) and populated in 2) - Run the test, which will start with the specified
workspace
and all projects in it
这篇关于使用随附的工作区项目运行Eclipse插件测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!