如何将测试项目添加到由JUnit创建的Eclipse环境进行插件测试? [英] How do i add a test project to the Eclipse environment created by JUnit for Plugin-testing?
问题描述
我认为JUnit至少正确地创建了一个test-eclipse,因为我可以在测试中使用像PlatformUI.getWorkbench()这样的调用。但是,如何在此测试中设置一个测试项目,我的JUnit测试可以使用? (我还需要设置一些项目更内部的东西,因为我正在检查natureIds和builderNames)
提前感谢您的答案!我也很乐意为eclipse插件编写测试的演练的链接感到高兴;)
一个插件,以便它们是执行的Eciipse运行时的一部分。然后,您可以访问org.eclipse.core.resources中的API来创建项目,文件夹和文件。
专门创建项目:
IProjectDescription description = ResourcesPlugin.getWorkspace()。newProjectDescription(name);
IProject project = ResourcesPlugin.getWorkspace()。getRoot()。getProject(name);
//在此描述中设置自然ID
try {
project.create(description,new NullProgressMonitor());
project.open(new NullProgressMonitor());
}
catch(CoreException e){
e.printStackTrace();
}
返回项目;
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 ;)
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;
这篇关于如何将测试项目添加到由JUnit创建的Eclipse环境进行插件测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!