Class AnnotatedBuilder

java.lang.Object
org.junit.runners.model.RunnerBuilder
org.junit.internal.builders.AnnotatedBuilder

public class AnnotatedBuilder extends RunnerBuilder
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 Details

  • Constructor Details

    • AnnotatedBuilder

      public AnnotatedBuilder(RunnerBuilder suiteBuilder)
  • Method Details