Run Eclipse Plug-in Test with included workspace p

2019-07-07 00:32发布

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);
        }
}

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?

1条回答
叼着烟拽天下
2楼-- · 2019-07-07 01:07

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):

  1. Open Eclipse and create a new workspace somewhere on the disc
  2. Add some sample projects to the new workspace
  3. Open an Eclipse instance which holds the Plug-in Test code
  4. In the JUnit Plug-in Test Launch Configuration, go to the Main tab

Launch configuration for a JUnit Plug-in Test

  1. Specify the workspace created in 1) and populated in 2)
  2. Run the test, which will start with the specified workspace and all projects in it
查看更多
登录 后发表回答