Run Eclipse Mock Test with Workspace Projects Included
I am writing a small Eclipse plugin and some tests for it. I am running plugin tests by specifying them to run in Headless Mode
. I want to access active Java projects in the workspace in these tests, but when I run them the workspace is empty. I am using the following code to get all Java projects (which works great):
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, projects are always empty. This is because it Headless Mode
launches a new instance of Eclipse with an empty workspace I guess. My question is, can I somehow specify that the tests should run on the current Eclipse instance? Or can I specify the projects I want to have in the newly created workspace?
source to share
I figured out an easy way to set up a test workspace
and wanted to share it with you (even if that means I'm answering my own question):
- Open
Eclipse
and create a newworkspace
one somewhere on disk - Add some sample projects to the new
workspace
- Open the instance
Eclipse
that contains the codePlug-in Test
- In
JUnit Plug-in Test Launch Configuration
go to the tabMain
- Indicate
workspace
created in 1) and entered in 2) - Run a test that will start with the specified
workspace
and all of its projects
source to share