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

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

问题描述

有没有办法在 Eclipse 中方便快速地从多个项目运行 JUnit-Tests?

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

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

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

有没有办法通过 Eclipse 中的几个项目的测试来做到这一点?最好是通过 Junit-Runner.如果有某种方法可以通过 Ant 作业快速实现它(因此之前不依赖于使用 ant 的完整构建),那也很好.

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.

推荐答案

您无法通过 UI 来完成.查看扩展点,JUnit 将收集的最高级别元素是项目.我想您可以编写一个插件来为工作集提供额外的上下文项/快捷方式,使工作集成为包资源管理器中的顶级项目,并将要在该工作集下方一起测试的项目分组.这样做的问题是你很难定义启用/禁用运行方式"贡献的上下文规则,我不确定语义是否扩展到工作集.因此,您必须编写某种包装器来迭代包含的项目并收集它们的测试类型.这似乎是一个有趣的小问题.我今天放学后可能会玩它.

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.

另一种(稍微少一点)hacky 方法是建立另一个项目,项目依赖于所有目标项目,然后使用链接的资源将所有测试类型带入新项目(我已经发布了一个 answer 在此之前描述了如何跨项目链接源).当然,如果您这样做,您还需要管理测试项目的依赖项.

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.

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

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.

如果您不喜欢使用插件或链接资源,那么您可能最好使用 Ant.

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天全站免登陆