在Eclipse中方便快捷地运行几个项目的Junit-Tests [英] Run Junit-Tests from several projects conveniently fast in Eclipse

查看:129
本文介绍了在Eclipse中方便快捷地运行几个项目的Junit-Tests的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



JUnit-Runner允许您定义一个包或一个文件夹,其中从所有包含的测试被执行。



有没有办法通过Eclipse内的几个项目的测试来做到这一点?
最好应该是通过Junit-Runner。如果有一些方法可以通过Ant-job快速完成(所以不需要依赖于ant的完整构建),那也是很好的。

解决方案

你不能通过UI进行。查看扩展点JUnit将收集的最高级元素是项目。我想你可以编写一个插件来为工作集提供一个附加的上下文项目/快捷方式,使工作设置包资源管理器中的顶级项目,并将要测试的项目组合在该工作集下方。
这样做的问题是您无法定义启用/禁用运行方式贡献的上下文规则,我不确定语义扩展到工作集。所以你必须编写一些包装器来迭代所包含的项目并收集他们的测试类型。这似乎是一个有趣的小问题。另外一个(稍微少一点的)hacky方式是在另一个项目中设置项目依赖关系到所有你的目标项目,然后再进行。使用链接的资源将所有测试类型带入新项目(我已经发布了一个 answer ,之前介绍如何在项目之间链接资源)。
当然,如果你这样做,你也需要管理测试项目的依赖关系。



如果您为每个项目创建了一个TestSuite,另外一个引用所有项目套件的TestSuite,您必须检查每个测试是否包含,这是容易出错的。



如果您不喜欢使用插件或链接资源,最好使用Ant。


Is there a way to run JUnit-Tests from several projects conveniently fast in Eclipse?

The JUnit-Runner lets you define a package or a folder where from all contained tests are executed.

Is there a way to do this with tests from several projects inside Eclipse? Preferably it should be via the Junit-Runner. If there is some way to have it fast via an Ant-job (so not depend on a complete build with ant before), that would be also nice.

解决方案

You can't do it through the UI. Looking at the extension-points the highest-level element JUnit will collect for is the Project. I suppose you could write a plugin to contribute an additional context item/shortcut for a working set, make working sets the top-level items in the package explorer and group the projects you want to test together below that working set. The problems with doing this is you'd have trouble defining the context rules for enabling/disabling the "run as" contribution and I'm not sure the semantics extend to working sets. So you'd have to write some sort of wrapper to iterate the contained projects and collect their test types. This does seem an interesting little problem. I might have a play with it after school today.

Another (slightly less) hacky way would be to set up another project with project dependencies on all your target projects, then use linked resources to bring all the test types into the new project (I've posted an answer before that describes how to link sources across projects). Of course if you do this you will need to manage the dependencies of the test project as well.

If you create a TestSuite for each project and another uber TestSuite that references all the projects' suites, you have to check every test is included, which is error-prone.

If you don't fancy mucking about with plugins or linked-resources, you're probably best off using Ant.

这篇关于在Eclipse中方便快捷地运行几个项目的Junit-Tests的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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