public interface SlowTests extends CategoryType {
}
public static class A {
@Test
public void a() {
fail();
}
@Category(SlowTests.class)
@Test
public void b() {
}
}
@Category(SlowTests.class)
public static class B {
@Test
public void c() {
}
}
public static class C {
@Test
public void d() {
fail();
}
}
@RunWith(Categories.class)
@IncludeCategory(SlowTests.class)
@SuiteClasses( { A.class, B.class, C.class })
public static class SlowTestSuite {
}
Saturday, November 14, 2009
Categories in JUnit 4.8
This is from the tests for the upcoming JUnit 4.8 release. It's the simplest-to-implement framework we could find for labelling tests with named categories, and running only tests with a given label.
Subscribe to:
Post Comments (Atom)
Can a single test have more than one category?
ReplyDeleteWhy are the categories interfaces? I don't really like, that I have to create empty interfaces. Would it be easier to use strings? Even though this opens up the possibilites for typos.
ReplyDeleteTo avoid using multiple annotations on test methods, one can use meta-annotations:
ReplyDelete@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Test
@Category(SlowTests.class)
public @interface SlowTest {
}
public static class A {
@SlowTest
public void a() {
fail();
}