Reputation: 597
I am trying to run a JUnit4 test using categories against an AllTests suite of tests. In example 1 running Suite3 works and example 2 running Suite2 produces the following exception.
java.lang.Exception: Category annotations on Parameterized classes are not supported on individual methods.
I need to generate the TestSuite as the test is executed.
Any suggestions for how to correct the problem? Thanks
example 1
@RunWith(Categories.class)
@IncludeCategory(SlowTest.class)
@SuiteClasses(AllTests3.class)
public class Suite3 {
}
@RunWith(Suite.class)
@SuiteClasses({
MathUtilTest.class, MathUtil2Test.class
})
public class AllTests3 {
}
example 2
@RunWith(Categories.class)
@IncludeCategory(SlowTest.class)
@SuiteClasses(AllTests2.class)
public class Suite2 {
}
public final class AllTests2 {
public static TestSuite suite() {
final TestSuite result = new TestSuite();
result.addTest(new JUnit4TestAdapter(MathUtilTest.class));
result.addTest(new JUnit4TestAdapter(MathUtil2Test.class));
return result;
}
private AllTests2() {
}
Upvotes: 3
Views: 189
Reputation: 6577
There are various related bugs in the latest stable version of JUnit 4 (4.12):
https://github.com/junit-team/junit4/issues/1203
Somebody committed a fix for the unreleased 4.13-SNAPSHOT version, which you can build and check out yourself by cloning their GitHub repo over at https://github.com/junit-team/junit4
However, I ran a couple of tests myself and have to conclude that the @Category annotation does work when used on your MathUtilTest class, but only if the class is annotated, the annotation is ignored when used on individual test methods.
Upvotes: 1