Run Junit-Tests from several projects conveniently fast in Eclipse

后端 未结 4 1189
离开以前
离开以前 2021-01-03 21:49

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

相关标签:
4条回答
  • 2021-01-03 22:16

    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.

    0 讨论(0)
  • 2021-01-03 22:24

    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

    0 讨论(0)
  • 2021-01-03 22:25

    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 { }
    
    0 讨论(0)
  • 2021-01-03 22:27

    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 {}
      
    0 讨论(0)
提交回复
热议问题