The newest version of JUnit does not contain a category annotation, like its rival TestNG or its distant cousin NUnit; however, this doesn’t mean you can’t easily categorize your tests. Much like pre-JUnit 4, the solution involves the use of suites; however, as anyone who is actually using JUnit 4 knows, suites, as we used to them, are history– they’ve been replaced with annotations.

Briefly, in JUnit 4, suites have been replaced by two annotations: @RunWith and @SuiteClasses. The @RunWith annotation requires it be set to the Suite class and then the @SuiteClasses annotation accepts a list of class to be run. It is this annotation that facilitates test categorization– for example, to run all unit tests, you would list them all as follows:

@RunWith(Suite.class)
@SuiteClasses({AccountEqualsTest.class, UserTest.class, CalcTest.class})
public class AllUnitTests {

}

Likewise, for component or system tests , you would create similar classes using the @SuiteClasses annotation. As you can see, traditional suite classes are gone in JUnit 4, but the same strategy for test categorization is essentially there– group like tests via suites.