Package org.junit.internal.builders
Class AnnotatedBuilder
java.lang.Object
org.junit.runners.model.RunnerBuilder
org.junit.internal.builders.AnnotatedBuilder
The
AnnotatedBuilder
is a strategy for constructing runners for test class that have been annotated with the
@RunWith
annotation. All tests within this class will be executed using the runner that was specified within
the annotation.
If a runner supports inner member classes, the member classes will inherit the runner from the enclosing class, e.g.:
@RunWith(MyRunner.class) public class MyTest { // some tests might go here public class MyMemberClass { @Test public void thisTestRunsWith_MyRunner() { // some test logic } // some more tests might go here } @RunWith(AnotherRunner.class) public class AnotherMemberClass { // some tests might go here public class DeepInnerClass { @Test public void thisTestRunsWith_AnotherRunner() { // some test logic } } public class DeepInheritedClass extends SuperTest { @Test public void thisTestRunsWith_SuperRunner() { // some test logic } } } } @RunWith(SuperRunner.class) public class SuperTest { // some tests might go here }The key points to note here are:
- If there is no RunWith annotation, no runner will be created.
- The resolve step is inside-out, e.g. the closest RunWith annotation wins
- RunWith annotations are inherited and work as if the class was annotated itself.
- The default JUnit runner does not support inner member classes, so this is only valid for custom runners that support inner member classes.
- Custom runners with support for inner classes may or may not support RunWith annotations for member classes. Please refer to the custom runner documentation.
- Since:
- 4.0
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildRunner
(Class<? extends Runner> runnerClass, Class<?> testClass) private Class<?>
getEnclosingClassForNonStaticMemberClass
(Class<?> currentTestClass) runnerForClass
(Class<?> testClass) Override to calculate the correct runner for a test class at runtime.Methods inherited from class org.junit.runners.model.RunnerBuilder
runners, runners, safeRunnerForClass
-
Field Details
-
CONSTRUCTOR_ERROR_FORMAT
- See Also:
-
suiteBuilder
-
-
Constructor Details
-
AnnotatedBuilder
-
-
Method Details
-
runnerForClass
Description copied from class:RunnerBuilder
Override to calculate the correct runner for a test class at runtime.- Specified by:
runnerForClass
in classRunnerBuilder
- Parameters:
testClass
- class to be run- Returns:
- a Runner
- Throws:
Exception
-
getEnclosingClassForNonStaticMemberClass
-
buildRunner
- Throws:
Exception
-