JUnit4 results differ from @SuiteClasses and TestSuite
I am trying to run a JUnit4 test using categories against the AllTests test suite. Example 1 running Suite3 and Example 2 running Suite2 throws the following exception.
java.lang.Exception: Category annotations on Parameterized classes are not supported on individual methods.
I need to generate a TestSuite as the test runs.
Any suggestions on how to fix the problem? Thanks to
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() {
}
source to share
There are various related bugs in the latest stable release of JUnit 4 (4.12):
https://github.com/junit-team/junit4/issues/1203
Someone made a fix for the unreleased 4.13-SNAPSHOT, which you can build and test yourself by cloning the GitHub repo at https://github.com/junit-team/junit4
However, I have run some tests myself and should conclude that the @Category annotation works when used in your MathUtilTest class, but only if the class is annotated, the annotation is ignored when used on separate test methods.
source to share