How do i add a test project to the Eclipse environment created by JUnit for Plugin-testing?

醉酒当歌 提交于 2019-12-11 08:21:30

问题


I currently am working on an Eclipse plugin which needs to access the selected project in the Project Explorer. I have to provide JUnit tests, but i'm very unsure how to write proper tests for an Eclipse plugin. I think JUnit is atleast properly creating a test-eclipse, since i can use calls like "PlatformUI.getWorkbench()" inside the test. But how do i setup a test-project inside this test-eclipse that my JUnit tests can work with? (I also need to set some of the project more internal stuff, since i'm checking natureIds and builderNames)

Thanks in advance for your answers! I would also be glad for links to a walkthrough of writing tests for an eclipse-plugin ;)


回答1:


You write your tests in a plug-in as well, so that they're part of the executing Eciipse runtime. Then you have access to the APIs from org.eclipse.core.resources to create projects, folders, and files.

For creating a project specifically:

IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(name);
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
// set nature IDs on the description here
try {
    project.create(description, new NullProgressMonitor());
    project.open(new NullProgressMonitor());
}
catch (CoreException e) {
    e.printStackTrace();
}
return project;


来源:https://stackoverflow.com/questions/20926138/how-do-i-add-a-test-project-to-the-eclipse-environment-created-by-junit-for-plug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!