I'm just exploring Junit4 an JunitExt for our project.
What we like to do is to distinguish between integration tests, unit
tests and database tests.
My idea now is to annotate the test methods with categories like
@Category("unit") or @Category("integration").
Now my question is, how to create different TestSuites that just run
one of the categories.
So something like:
------------------------
@RunWith(Suite.class)
@Suite.SuiteClasses( { MyTest.class})
@Filter(category="unit")
public class AllTests {
}
------------------------
Thanks
Matt
Matthias
public class CategorySuite extends Suite {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface RunCategory {
/** The category name. */
String value();
}
/**
* Internal use only.
*/
public CategorySuite(Class<?> klass) throws InitializationError {
super(klass);
try {
filter(new CategoryFilter(getCategory(klass)));
} catch (NoTestsRemainException e) {
}
}
private static String getCategory(Class<?> klass) throws
InitializationError {
RunCategory category = klass.getAnnotation(RunCategory.class);
if (category == null)
throw new InitializationError(String.format("class '%s'
must have a RunCategory annotation",
klass.getName()));
return category.value();
}
}