Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run JUnit tests from multiple packages in Eclipse?

People also ask

Is parallel execution possible in JUnit?

Yes, You can. Show activity on this post. JUnit Toolbox provides JUnit runners for parallel execution of tests.

Can JUnit tests be debugged in Eclipse?

To debug a JUnit test via Eclipse, simply place your breakpoints as expected, and then right click the test method and choose “Debug As” -> “JUnit Test”. The test will start and will pause when the breakpoint is hit.


Yes, it is possible. The easiest way for me at least is to add a test suite class. It can 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 class that you import no matter what package it is in. To run this in eclipse you just right click the AllTests class and run it as JUnit test. It will then run all the tests you define in @SuiteClasses.

This will work with linked sources as well, I use it all the time.


An other way:

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

enter image description here

Then open run configurations, create a new configuration and then set "Run all tests..." as exemplified in the image below.

enter image description here


Maybe not exactly what the original question was, but you can easily run all tests of a whole Project, by simply right-clicking the project -> Run As JUnitTest. Don't worry where the annotated classes reside, this will be scanned.

This does not work if applied to the test-src-folder or a package with subpackes. Quite a shame actually -.-


I'm sure u can tweak this a bit. Make a Collection of the CLASSES_DIR property and loop over it in the findClasses method. (junit4)

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


I beleieve that you can add all your test packages to a single directory. If you right click on this directory, then you should find the "run as -> JUnit test" option available. This will run all tests contained in the directory and will catch anything you've added. Any new tests get put in there with the rest of them and whatever package name you have it doesn't matter. Hope that helps