Class OrderedRunner

  • All Implemented Interfaces:
    org.junit.runner.Describable, org.junit.runner.manipulation.Filterable, org.junit.runner.manipulation.Sortable

    public class OrderedRunner
    extends org.junit.runners.BlockJUnit4ClassRunner
    This class extends org.junit.runners.BlockJUnit4ClassRunner and overrides the computeTestMethods() method to guarantee that test methods are run in a user-defined order using the TestIndex annotation. While JUnit discourages test method dependencies because increases test maintenance difficultly, breaking a complex test down to a series of simple, dependent test methods is necessary at times.

    An example using this class runner:

    
     @RunWith(OrderedRunner.class)
     public final class MyTest
     {
         @Test
         @TestIndex(index=0)
         public void test0()
         {
             ...
         }
    
         @Test
         @TestIndex(index=1)
         public void test1
         {
             ...
         }
     }

    Note: this is not meant to replace org.junit.runner.manipulation.Sortable interface since that interface should not be used to cope with test method dependencies (as per the JUnit documentation).

    Author:
    Charles Rapp
    • Constructor Summary

      Constructors 
      Constructor Description
      OrderedRunner​(Class<?> clazz)
      Creates a new OrderedRunner instance for the given test class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected List<org.junit.runners.model.FrameworkMethod> computeTestMethods()
      Returns the test methods list sorted according to their test index values.
      • Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner

        collectInitializationErrors, createTest, describeChild, getChildren, getTestRules, isIgnored, methodBlock, methodInvoker, possiblyExpectingExceptions, rules, runChild, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor, withAfters, withBefores, withPotentialTimeout
      • Methods inherited from class org.junit.runners.ParentRunner

        childrenInvoker, classBlock, classRules, createTestClass, filter, getDescription, getName, getRunnerAnnotations, getTestClass, run, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withAfterClasses, withBeforeClasses
      • Methods inherited from class org.junit.runner.Runner

        testCount
    • Constructor Detail

      • OrderedRunner

        public OrderedRunner​(Class<?> clazz)
                      throws org.junit.runners.model.InitializationError
        Creates a new OrderedRunner instance for the given test class.
        Parameters:
        clazz - the Java class containing the test methods.
        Throws:
        org.junit.runners.model.InitializationError - if this constructor fails.
    • Method Detail

      • computeTestMethods

        protected List<org.junit.runners.model.FrameworkMethod> computeTestMethods()
        Returns the test methods list sorted according to their test index values.
        Overrides:
        computeTestMethods in class org.junit.runners.BlockJUnit4ClassRunner
        Returns:
        the sorted test method list.