Run Junit-Tests from several projects conveniently fast in Eclipse

旧城冷巷雨未停 提交于 2019-12-18 18:49:06

问题


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.


回答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.

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.




回答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.

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



回答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)

Check here for more informations:

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



来源:https://stackoverflow.com/questions/1137479/run-junit-tests-from-several-projects-conveniently-fast-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!