JUnit 4 has the concept of categories that allows to group the tests and select the tests by those groups.
We define interfaces for the groups we are interested in:
public interface SlowTests { /* category marker */ }
Then we can use the "Category" tag to mark the test.
@Category(SlowTests.class)
@Test
public void a()
Then we create a Test Suite to select the category:
@RunWith(Categories.class)
@IncludeCategory(SlowTests.class)
@Suite.SuiteClasses( { TestA.class, TestB.class }) // Note that Categories is a kind of Suite
public class SlowTestSuite
{
}
We can then run the Suite with a Test Runner:
Result result = JUnitCore.runClasses(SlowTestSuite.class);
We can apply multiple Categories to one test case.
Ex:
public class TestA
{
@Category({SlowTests.class, FastTests.class})
@Test
public void a()
{
We can apply a Category to a whole class also.
@Category({SlowTests.class, FastTests.class})
public class TestB
{
We can also include more than one category in the suite test.
@IncludeCategory( {SlowTests.class, FastTests.class} )