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

时间:2022-05-13 00:10:29

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

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

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

JUnit-Runner允许您定义包含所有包含的测试的包或文件夹。

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.

有没有办法用Eclipse中的几个项目进行测试?最好是通过Junit-Runner。如果有一些方法可以通过Ant-job快速获取它(所以不依赖于之前使用ant的完整构建),那也很好。

4 个解决方案

#1


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.

你不能通过UI来做到这一点。查看扩展点,JUnit将收集的*元素是项目。我想你可以编写一个插件来为工作集贡献一个额外的上下文项/快捷方式,make work设置包浏览器中的*项,并将你想要在该工作集下面一起测试的项目分组。执行此操作的问题是您无法定义启用/禁用“运行方式”贡献的上下文规则,并且我不确定语义是否扩展到工作集。因此,您必须编写某种包装器来迭代包含的项目并收集它们的测试类型。这似乎是一个有趣的小问题。我今天放学后可能会玩它。

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.

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

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.

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

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

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

#2


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.

从Eclipse中跨多个项目执行JUnit测试实际上非常容易。看看Classpath Suite。这不是标准的JUnit跑步者,但你没有提到这个要求来自哪里,所以我不确定这是否会影响你。

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. 根据要测试的所有项目创建Eclipse项目。

  3. Write a simple test suite including everything:

    写一个简单的测试套件,包括一切:

    @RunWith(ClasspathSuite.class)  
    public class MySuite {}
    

#3


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 { }

#4


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)

我不确定你不能从UI做到这一点,但是从蚂蚁开始,即使你没有使用ant构建插件也是可能的。然而,这种方法并非如此简单,但一旦设置好,事情就很酷了; o)

Check here for more informations:

点击此处查看更多信息:

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

#1


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.

你不能通过UI来做到这一点。查看扩展点,JUnit将收集的*元素是项目。我想你可以编写一个插件来为工作集贡献一个额外的上下文项/快捷方式,make work设置包浏览器中的*项,并将你想要在该工作集下面一起测试的项目分组。执行此操作的问题是您无法定义启用/禁用“运行方式”贡献的上下文规则,并且我不确定语义是否扩展到工作集。因此,您必须编写某种包装器来迭代包含的项目并收集它们的测试类型。这似乎是一个有趣的小问题。我今天放学后可能会玩它。

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.

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

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.

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

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

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

#2


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.

从Eclipse中跨多个项目执行JUnit测试实际上非常容易。看看Classpath Suite。这不是标准的JUnit跑步者,但你没有提到这个要求来自哪里,所以我不确定这是否会影响你。

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. 根据要测试的所有项目创建Eclipse项目。

  3. Write a simple test suite including everything:

    写一个简单的测试套件,包括一切:

    @RunWith(ClasspathSuite.class)  
    public class MySuite {}
    

#3


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 { }

#4


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)

我不确定你不能从UI做到这一点,但是从蚂蚁开始,即使你没有使用ant构建插件也是可能的。然而,这种方法并非如此简单,但一旦设置好,事情就很酷了; o)

Check here for more informations:

点击此处查看更多信息:

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