6

I want to run Junit test suites that contain various test classes.

Of all tests, i want to exclude test methods annotated with a certain annotation.

I am aware of the @Ignore annotation but i do not want to use it here because i want to be able to ignore different test methods if i call the tests from different test suites.

I have tried it and it does not work. Running my suite without @ExcludeCategory(IgnoreMeForSpecialReason.class) runs the same amount of test cases as are run with @ExcludeCategory(IgnoreMeForSpecialReason.class)

To illustrate it:

This suite

//version 1
@RunWith(Categories.class)
@ExcludeCategory(IgnoreForSpecialReasonA.class)
@SuiteClasses({
    // add your test classes here
    Module1Test.class,
    Module2Test.class,
    Module3Test.class
})

public class MySuiteA
{

}

runs the same amount of tests as does this version of the suite:

//version 2
@RunWith(Categories.class)
//@ExcludeCategory(IgnoreForSpecialReasonA.class)
@SuiteClasses({
    // add your test classes here
    Module1Test.class,
    Module2Test.class,
    Module3Test.class
})

public class MySuiteA
{

}

One test method of Module1Test is annotated with the @IgnoreForSpecialReasonA Annotation. That method should be skipped in version1 of my example, but it is run.

How can i achieve that @ExcludeCategory actually works with suites?

Cheers!

nemoo
  • 3,269
  • 4
  • 38
  • 51

1 Answers1

3

@ExcludeCategory should work with @Category.

Make sure your ignore methods/classes are annotated with @Category(IgnoreForSpecialReasonA.class).

Meredith
  • 3,928
  • 4
  • 33
  • 58
卢声远 Shengyuan Lu
  • 31,208
  • 22
  • 85
  • 130
  • That was it, i had just annotated the method directly instead of doing it through the @Category annotation. thanks! – nemoo Jun 20 '11 at 08:46