JUnit 4 Test Suites
You can create a suite like so. For example an AllTest
suite would look something like this.
package my.package.tests;
@RunWith(Suite.class)
@SuiteClasses({
testMyService.class,
testMyBackend.class,
...
})
public class AllTests {}
Now you can run this in a couple different ways:
- right-click and run in Eclipse as Junit test
- create a runable Java Application; Main class='org.junit.runner.JUnitCore' and Args='my.package.tests.AllTests'
run from the command line:
$ java -cp build/classes/:/usr/share/java/junit4.jar:/usr/share/java/hamcrest-core.jar org.junit.runner.JUnitCore my.package.tests.AllTests
import org.junit.runners.Suite;
import org.junit.runner.RunWith;
@RunWith(Suite.class)
@Suite.SuiteClasses({TestClass1.class, TestClass2.class})
public class TestSuite {
//nothing
}
I think TestSuite has fallen out of favor. That might have been the style before 4.x, but it's not now as far as I know.
I just annotate the tests I want and then run the class. All the annotated tests are run. I might use Ant, but most of the time I have IntelliJ run them for me.