在 Eclipse 中方便快速地从多个项目运行 Junit 测试

发布于 2024-07-26 23:17:40 字数 221 浏览 4 评论 0原文

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

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

有没有办法通过 Eclipse 内的多个项目的测试来做到这一点? 最好是通过 Junit-Runner 进行。 如果有某种方法可以通过 Ant 作业快速实现(因此不依赖于之前使用 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

土豪 2024-08-02 23:17:41

实际上,在 Eclipse 中跨多个项目执行 JUnit 测试非常容易。 查看类路径套件。 它不是标准的 JUnit 运行程序,但您没有提到该要求来自哪里,所以我不确定这是否会影响您。

所有使用信息都在该页面上,但总结一下:

  1. 根据您要测试的所有项目创建一个 Eclipse 项目。
  2. 编写一个简单的测试套件,包括所有内容:

    @RunWith(ClasspathSuite.class)   
      公共类 MySuite {} 
      

It’s actually quite easy to perform JUnit tests across multiple projects from within Eclipse. Have a look at Classpath Suite. It’s not with the standard JUnit runner, but you did not mention where that requirement came from, so I’m not sure whether this will affect you.

All the usage information is on that page, but to summarize:

  1. Create an Eclipse project depending on all the projects you want to test.
  2. Write a simple test suite including everything:

    @RunWith(ClasspathSuite.class)  
    public class MySuite {}
    
没企图 2024-08-02 23:17:41

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

另一种(稍微少一些)的hacky方法是设置另一个项目,其项目依赖于所有目标项目,然后使用链接的资源将所有测试类型引入新项目(我已经发布了 回答之前描述了如何跨项目链接源)。
当然,如果您这样做,您还需要管理测试项目的依赖项。

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

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

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.

开始看清了 2024-08-02 23:17:41

您可以定义一个依赖于其他项目的单独项目,其中包含引用不同项目中的各个测试或套件的套件。 像这样的事情:

@RunWith(Suite.class)
@Suite.SuiteClasses( { FirstProjectSuite.class, SecondProjectSuite.class} )
public class AllSuites { }

You could define a separate project that depends on the other projects, which contains a suite referencing the individual tests or suites from the different projects. Something like this:

@RunWith(Suite.class)
@Suite.SuiteClasses( { FirstProjectSuite.class, SecondProjectSuite.class} )
public class AllSuites { }
苏佲洛 2024-08-02 23:17:41

我不确定你不能从 UI 中做到这一点,但从 ant 中,即使你不使用 ant 构建插件,也是可能的。 尽管如此,这个方法并不是那么简单,但是一旦设置好,事情就很酷;o)

请在此处查看更多信息:

http://www.eclipse.org/articles/article.php?file=Article-PDEJUnitAntAutomation/index.html

I am not sure you can't do it from UI but from ant it's possible even if you are not building you plugins using ant. Nevertheless this method is not so trivial but once it's set up, things are cool ;o)

Check here for more informations:

http://www.eclipse.org/articles/article.php?file=Article-PDEJUnitAntAutomation/index.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文