如何将测试项目添加到由JUnit创建的Eclipse环境进行插件测试? [英] How do i add a test project to the Eclipse environment created by JUnit for Plugin-testing?

查看:255
本文介绍了如何将测试项目添加到由JUnit创建的Eclipse环境进行插件测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Eclipse插件,需要在Project Explorer中访问所选项目。我必须提供JUnit测试,但我非常不确定如何为Eclipse插件编写适当的测试。
我认为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆