Can I run JUnit tests from multiple packages in Eclipse?

Is it possible to run JUnit tests for multiple packages at the same time without manually creating test suites.

For example, if I have a hierarchy:

code.branchone
code.branchone.aaa
code.branchone.bbb
code.branchtwo
code.branchtwo.aaa
code.branchtwo.bbb

Is it possible:

  • Run all tests in code.branchone and in stream packages
  • Run all the tests in the code.branchone.aaa and code.branchtwo.bbb sections

The problem that I see with creating test suites manually is that when new tests appear, you may forget to add them.

+47
java eclipse junit testing
Jan 05 '09 at 14:16
source share
7 answers

Yes it is possible. The easiest way for me is to add a test suite class. It might look like this:

package tests; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; import tests.message.ATest; import tests.validator.BTest; import tests.validator.CTest; import tests.validator.DTest; @RunWith(Suite.class) @SuiteClasses({ ATest.class, BTest.class, CTest.class, DTest.class }) public class AllTests { } 

This will allow you to test any imported class no matter what package it is in. To run this in eclipse, you just right-click the AllTests class and run it as a JUnit test. Then it will run all the tests you define in @SuiteClasses .

This will work with related sources, I use it all the time.

+21
Feb 17 '13 at 16:12
source share
— -

Another way:

Click on the black triangle indicated by the red rectangle in the image below (in your Eclipse, not here :).

enter image description here

Then open the launch configurations, create a new configuration, and then set "Run all tests ..." as shown in the figure below.

enter image description here

+18
Nov 22 '12 at 20:22
source share

Perhaps not quite what was in the original question, but you can easily run all the tests of the entire project by simply right-clicking the project → Run As JUnitTest. Do not worry where the annotated classes are located, this will be checked.

This does not work if applied to the test-src folder or package with subpackages. Pretty ashamed actually -.-

+9
Jul 03 '13 at 14:36
source share

I am sure you can adjust this a bit. Create a collection of the CLASSES_DIR property and flip it in the findClasses method. (Junit4)

http://burtbeckwith.com/blog/?p=52

+3
Jan 05 '09 at 14:51
source share

Of course, right-click the packages you need and select Run As ... JUnit Test

+2
Jan 05 '09 at 14:36
source share

I suggest that you can add all test packages to the same directory. If you right-click on this directory, you should find the option "run as → JUnit test". This will run all the tests contained in the directory and catch everything you added. Any new tests get there along with the rest, and any package name you have does not matter. Hope that helps

+1
Jan 05 '09 at 14:35
source share

In Eclipse, in the debug / launch settings, you can select the following options:

  • Run one test
  • Run all tests in the selected folder of the project, package or source

I think the second option is your friend in this case.

+1
Jan 05 '09 at 14:38
source share



All Articles