Package org.junit.internal.builders
Class AnnotatedBuilder
- java.lang.Object
-
- org.junit.runners.model.RunnerBuilder
-
- org.junit.internal.builders.AnnotatedBuilder
-
public class AnnotatedBuilder extends RunnerBuilder
TheAnnotatedBuilder
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:
RunnerBuilder
,RunWith
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
CONSTRUCTOR_ERROR_FORMAT
private RunnerBuilder
suiteBuilder
-
Constructor Summary
Constructors Constructor Description AnnotatedBuilder(RunnerBuilder suiteBuilder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Runner
buildRunner(java.lang.Class<? extends Runner> runnerClass, java.lang.Class<?> testClass)
private java.lang.Class<?>
getEnclosingClassForNonStaticMemberClass(java.lang.Class<?> currentTestClass)
Runner
runnerForClass(java.lang.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 Detail
-
CONSTRUCTOR_ERROR_FORMAT
private static final java.lang.String CONSTRUCTOR_ERROR_FORMAT
- See Also:
- Constant Field Values
-
suiteBuilder
private final RunnerBuilder suiteBuilder
-
-
Constructor Detail
-
AnnotatedBuilder
public AnnotatedBuilder(RunnerBuilder suiteBuilder)
-
-
Method Detail
-
runnerForClass
public Runner runnerForClass(java.lang.Class<?> testClass) throws java.lang.Exception
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:
java.lang.Exception
-
getEnclosingClassForNonStaticMemberClass
private java.lang.Class<?> getEnclosingClassForNonStaticMemberClass(java.lang.Class<?> currentTestClass)
-
-