Class Categories
- java.lang.Object
-
- org.junit.runner.Runner
-
- org.junit.runners.ParentRunner<Runner>
-
- org.junit.runners.Suite
-
- org.junit.experimental.categories.Categories
-
- All Implemented Interfaces:
Describable
,Filterable
,Sortable
public class Categories extends Suite
From a given set of test classes, runs only the classes and methods that are annotated with either the category given with the @IncludeCategory annotation, or a subtype of that category.Note that, for now, annotating suites with
@Category
has no effect. Categories must be annotated on the direct method or class.Example:
public interface FastTests { } public interface SlowTests { } public interface SmokeTests } public static class A { @Test public void a() { fail(); } @Category(SlowTests.class) @Test public void b() { } @Category({FastTests.class, SmokeTests.class}) @Test public void c() { } } @Category({SlowTests.class, FastTests.class}) public static class B { @Test public void d() { } } @RunWith(Categories.class) @IncludeCategory(SlowTests.class) @SuiteClasses({A.class, B.class}) // Note that Categories is a kind of Suite public static class SlowTestSuite { // Will run A.b and B.d, but not A.a and A.c }
Example to run multiple categories:
@RunWith(Categories.class) @IncludeCategory({FastTests.class, SmokeTests.class}) @SuiteClasses({A.class, B.class}) public static class FastOrSmokeTestSuite { // Will run A.c and B.d, but not A.b because it is not any of FastTests or SmokeTests }
- Version:
- 4.12
- See Also:
- Categories at JUnit wiki
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Categories.CategoryFilter
static interface
Categories.ExcludeCategory
static interface
Categories.IncludeCategory
-
Nested classes/interfaces inherited from class org.junit.runners.Suite
Suite.SuiteClasses
-
-
Constructor Summary
Constructors Constructor Description Categories(java.lang.Class<?> klass, RunnerBuilder builder)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static void
assertNoCategorizedDescendentsOfUncategorizeableParents(Description description)
private static void
assertNoDescendantsHaveCategoryAnnotations(Description description)
private static boolean
canHaveCategorizedChildren(Description description)
private static java.util.Set<java.lang.Class<?>>
createSet(java.lang.Class<?>... t)
private static java.util.Set<java.lang.Class<?>>
getExcludedCategory(java.lang.Class<?> klass)
private static java.util.Set<java.lang.Class<?>>
getIncludedCategory(java.lang.Class<?> klass)
private static boolean
hasAssignableTo(java.util.Set<java.lang.Class<?>> assigns, java.lang.Class<?> to)
private static boolean
isAnyExcluded(java.lang.Class<?> klass)
private static boolean
isAnyIncluded(java.lang.Class<?> klass)
-
Methods inherited from class org.junit.runners.Suite
describeChild, emptySuite, getChildren, runChild
-
Methods inherited from class org.junit.runners.ParentRunner
childrenInvoker, classBlock, classRules, collectInitializationErrors, createTestClass, filter, getDescription, getName, getRunnerAnnotations, getTestClass, isIgnored, run, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withAfterClasses, withBeforeClasses
-
-
-
-
Constructor Detail
-
Categories
public Categories(java.lang.Class<?> klass, RunnerBuilder builder) throws InitializationError
- Throws:
InitializationError
-
-
Method Detail
-
getIncludedCategory
private static java.util.Set<java.lang.Class<?>> getIncludedCategory(java.lang.Class<?> klass)
-
isAnyIncluded
private static boolean isAnyIncluded(java.lang.Class<?> klass)
-
getExcludedCategory
private static java.util.Set<java.lang.Class<?>> getExcludedCategory(java.lang.Class<?> klass)
-
isAnyExcluded
private static boolean isAnyExcluded(java.lang.Class<?> klass)
-
assertNoCategorizedDescendentsOfUncategorizeableParents
private static void assertNoCategorizedDescendentsOfUncategorizeableParents(Description description) throws InitializationError
- Throws:
InitializationError
-
assertNoDescendantsHaveCategoryAnnotations
private static void assertNoDescendantsHaveCategoryAnnotations(Description description) throws InitializationError
- Throws:
InitializationError
-
canHaveCategorizedChildren
private static boolean canHaveCategorizedChildren(Description description)
-
hasAssignableTo
private static boolean hasAssignableTo(java.util.Set<java.lang.Class<?>> assigns, java.lang.Class<?> to)
-
createSet
private static java.util.Set<java.lang.Class<?>> createSet(java.lang.Class<?>... t)
-
-