Is it possible to exclude multiple categories in JUnit 4?
I would like to do something like:
@RunWith(Categories.class)
@Categories.IncludeCategory(Small.class)
@Categories.ExcludeCate开发者_开发百科gory({Manual.class, NonFunctional.class})
@Suite.SuiteClasses(AllTests.class)
public class SmallTests {
}
but ExcludeCategories accepts only one class, not an array of classes.
This will be supported in JUnit 4.12 version, see https://github.com/junit-team/junit/blob/master/src/main/java/org/junit/experimental/categories/Categories.java
It looks like runtime-suite may provide another workaround/solution.
There's a JUnit 4 feature request for this: https://github.com/junit-team/junit/issues/146
This link also suggests a workaround:
There is a not-so-beatiful workaround. You can get multiple includes or excludes if you create an inheritance hierarchy of suites and exclude one category on each level.
精彩评论