Creation of TestSuites using categories

1 view
Skip to first unread message

Matthias Lübken

unread,
Apr 11, 2007, 12:39:10 PM4/11/07
to junitext-dev
Hi

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 Lübken

unread,
Apr 12, 2007, 9:43:11 AM4/12/07
to junitext-dev

Hi
I've created my own Suite class.

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();
}
}

Reply all
Reply to author
Forward
0 new messages