Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore junit tests via @ExcludeCategory within a test suite

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!

like image 963
nemoo Avatar asked Jun 17 '11 14:06

nemoo


1 Answers

@ExcludeCategory should work with @Category.

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

like image 98
卢声远 Shengyuan Lu Avatar answered Sep 16 '22 13:09

卢声远 Shengyuan Lu