Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Eclipse Plug-in Test with included workspace projects

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?

like image 220
WeSt Avatar asked May 17 '26 12:05

WeSt


1 Answers

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
like image 112
WeSt Avatar answered May 19 '26 01:05

WeSt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!