Run Junit-Tests from several projects conveniently fast in Eclipse

◇◆丶佛笑我妖孽 提交于 2019-11-30 17:09:07
Rich Seller

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.

Michael Piefel

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

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

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

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