Class FactoryRunner

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

    public class FactoryRunner
    extends org.junit.runners.BlockJUnit4ClassRunner
    A helper method that can be used to modify how JUnit executes a test suite. Add annotation @RunWith(FactoryRunner.class) to the JUnit test to hook this helper to the JUnit test suite. When executing the test suite with JUnit, all methods of the test suite that are annotated with TestFactory will be executed before all other tests. Each of these methods dynamically adds a number of JUnit tests to the test suite.
    Author:
    Ted Young
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.LinkedList<org.junit.runners.model.FrameworkMethod> tests  
    • Constructor Summary

      Constructors 
      Constructor Description
      FactoryRunner​(java.lang.Class<?> clazz)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.Collection<? extends org.junit.runners.model.FrameworkMethod> computeFactoryTests()  
      protected java.util.List<org.junit.runners.model.FrameworkMethod> computeTestMethods()
      protected void computeTests()  
      protected void validateInstanceMethods​(java.util.List<java.lang.Throwable> errors)
      This method overrides the original method validateInstanceMethods(...) of BlockJUnit4ClassRunner to avoid a crash of the JUnit test suite caused by adding FactoryTests to the test suite before pre-defined tests are loaded.
      • Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner

        collectInitializationErrors, createTest, describeChild, getChildren, getTestRules, isIgnored, methodBlock, methodInvoker, possiblyExpectingExceptions, rules, runChild, testName, validateConstructor, validateFields, 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • tests

        protected java.util.LinkedList<org.junit.runners.model.FrameworkMethod> tests
    • Constructor Detail

      • FactoryRunner

        public FactoryRunner​(java.lang.Class<?> clazz)
                      throws org.junit.runners.model.InitializationError
        Throws:
        org.junit.runners.model.InitializationError
    • Method Detail

      • computeTests

        protected void computeTests()
                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • computeFactoryTests

        protected java.util.Collection<? extends org.junit.runners.model.FrameworkMethod> computeFactoryTests()
                                                                                                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • computeTestMethods

        protected java.util.List<org.junit.runners.model.FrameworkMethod> computeTestMethods()
        Overrides:
        computeTestMethods in class org.junit.runners.BlockJUnit4ClassRunner
        See Also:
        BlockJUnit4ClassRunner.computeTestMethods()
      • validateInstanceMethods

        protected void validateInstanceMethods​(java.util.List<java.lang.Throwable> errors)
        This method overrides the original method validateInstanceMethods(...) of BlockJUnit4ClassRunner to avoid a crash of the JUnit test suite caused by adding FactoryTests to the test suite before pre-defined tests are loaded. The original method is marked @Deprecated. TODO: Remove this overriding method once the original is removed from the JUnit framework.
        Overrides:
        validateInstanceMethods in class org.junit.runners.BlockJUnit4ClassRunner