public class LoadTimeWeavableTestRunner extends org.junit.runner.Runner implements org.junit.runner.manipulation.Filterable, org.junit.runner.manipulation.Sortable
Runner which uses a custom classloader with a copy of the classpath and allows
 for transformers to be added to the ClassLoader for load-time weaving.
 Useful when writing tests that use JPA with EclipseLink since it depends upon load-time weaving.
In order to use this class, you must have a BootstrapTest annotation available somewhere in the hierarchy
 of your test class (usually on the same class where the RunWith annotation is specified which references this
 runner class). This informs the runner about a test that it can run to execute any one-time initialization for
 the test suite. Ideally, this bootstrap test will execute code which loads JPA persistence units and any associated
 ClassFileTransformers for load-time weaving. This is necessary because it is common for an integration test to have
 references in the test class itself to JPA entities which need to be weaved. When this occurs, if the persistence
 units and ClassFileTransformers are not properly loaded before the entity classes are loaded by the classloader, then
 instrumentation will (silently!) fail to occur.
Much of the code in this class was copied from the JUnit ParentRunner, BlockJUnit4ClassRunner, and TomcatInstrumentableClassLoader.
| Constructor and Description | 
|---|
| LoadTimeWeavableTestRunner(Class<?> testClass)Constructs a new  ParentRunnerthat will run@TestClass | 
| Modifier and Type | Method and Description | 
|---|---|
| protected org.junit.runners.model.Statement | childrenInvoker(org.junit.runner.notification.RunNotifier notifier)Returns a  Statement: CallrunChild(org.junit.runners.model.FrameworkMethod, org.junit.runner.notification.RunNotifier)on each object returned bygetChildren()(subject to any imposed
 filter and sort) | 
| protected org.junit.runners.model.Statement | classBlock(org.junit.runner.notification.RunNotifier notifier)Constructs a  Statementto run all of the tests in the test class. | 
| protected List<org.junit.rules.TestRule> | classRules() | 
| protected void | collectInitializationErrors(List<Throwable> errors)Adds to  errorsa throwable for each problem noted with the test class (available fromgetTestClass()). | 
| protected List<org.junit.runners.model.FrameworkMethod> | computeOriginalTestMethods() | 
| protected List<org.junit.runners.model.FrameworkMethod> | computeTestMethods()Returns the methods that run tests. | 
| protected Object | createTest()Returns a new fixture for running a test. | 
| protected org.junit.runner.Description | describeChild(org.junit.runners.model.FrameworkMethod method)Returns a  Descriptionforchild, which can be assumed to
 be an element of the list returned bygetChildren() | 
| protected org.junit.runner.Description | describeOriginalChild(org.junit.runners.model.FrameworkMethod method) | 
| void | filter(org.junit.runner.manipulation.Filter filter) | 
| protected List<org.junit.runners.model.FrameworkMethod> | getChildren()Returns a list of objects that define the children of this Runner. | 
| protected ClassLoader | getCustomClassLoader() | 
| org.junit.runner.Description | getDescription() | 
| protected String | getName()Returns a name used to describe this Runner | 
| protected List<org.junit.runners.model.FrameworkMethod> | getOriginalChildren() | 
| org.junit.runners.model.TestClass | getOriginalTestClass()Returns the original test class that was passed to this test runner. | 
| protected Annotation[] | getRunnerAnnotations() | 
| org.junit.runners.model.TestClass | getTestClass()Returns a  TestClassobject wrapping the class to be executed. | 
| protected List<org.junit.rules.TestRule> | getTestRules(Object target) | 
| protected org.junit.runners.model.Statement | methodBlock(org.junit.runners.model.FrameworkMethod method)Returns a Statement that, when executed, either returns normally if
  methodpasses, or throws an exception ifmethodfails. | 
| protected org.junit.runners.model.Statement | methodInvoker(org.junit.runners.model.FrameworkMethod method,
             Object test)Returns a  Statementthat invokesmethodontest | 
| protected org.junit.runners.model.Statement | possiblyExpectingExceptions(org.junit.runners.model.FrameworkMethod method,
                           Object test,
                           org.junit.runners.model.Statement next)Deprecated. 
 Will be private soon: use Rules instead | 
| protected List<org.junit.rules.MethodRule> | rules(Object target) | 
| void | run(org.junit.runner.notification.RunNotifier notifier) | 
| protected boolean | runBootstrapTest(org.junit.runner.notification.RunNotifier notifier,
                org.junit.runners.model.TestClass testClass) | 
| protected void | runChild(org.junit.runners.model.FrameworkMethod method,
        org.junit.runner.notification.RunNotifier notifier)Runs the test corresponding to  child, which can be assumed to be
 an element of the list returned bygetChildren(). | 
| protected void | runLeaf(org.junit.runners.model.Statement statement,
       org.junit.runner.Description description,
       org.junit.runner.notification.RunNotifier notifier)Runs a  Statementthat represents a leaf (aka atomic) test. | 
| protected void | setTestMethod(Object test,
             Method method)Sets the  Methodon the test case if it isMethodAware | 
| protected void | setTestName(Object test,
           Method testMethod) | 
| void | sort(org.junit.runner.manipulation.Sorter sorter) | 
| protected String | testName(org.junit.runners.model.FrameworkMethod method)Returns the name that describes  methodforDescriptions. | 
| protected void | validateConstructor(List<Throwable> errors)Adds to  errorsif the test class has more than one constructor,
 or if the constructor takes parameters. | 
| protected void | validateFields(List<Throwable> errors) | 
| protected void | validateInstanceMethods(List<Throwable> errors)Deprecated. 
 unused API, will go away in future version | 
| protected void | validateNoNonStaticInnerClass(List<Throwable> errors) | 
| protected void | validateOnlyOneConstructor(List<Throwable> errors)Adds to  errorsif the test class has more than one constructor
 (do not override) | 
| protected void | validatePublicVoidNoArgMethods(Class<? extends Annotation> annotation,
                              boolean isStatic,
                              List<Throwable> errors)Adds to  errorsif any method in this class is annotated withannotation, but:
 
 is not public, or
 takes parameters, or
 returns something other than void, or
 is static (givenisStatic is false), or
 is not static (givenisStatic is true). | 
| protected void | validateTestMethods(List<Throwable> errors)Adds to  errorsfor each method annotated with@Testthat
 is not a public, void instance method with no arguments. | 
| protected void | validateZeroArgConstructor(List<Throwable> errors)Adds to  errorsif the test class's single constructor takes
 parameters (do not override) | 
| protected org.junit.runners.model.Statement | withAfterClasses(org.junit.runners.model.Statement statement)Returns a  Statement: run all non-overridden@AfterClassmethods on this class
 and superclasses before executingstatement; all AfterClass methods are
 always executed: exceptions thrown by previous steps are combined, if
 necessary, with exceptions from AfterClass methods into aMultipleFailureException. | 
| protected org.junit.runners.model.Statement | withAfters(org.junit.runners.model.FrameworkMethod method,
          Object target,
          org.junit.runners.model.Statement statement)Deprecated. 
 Will be private soon: use Rules instead | 
| protected org.junit.runners.model.Statement | withBeforeClasses(org.junit.runners.model.Statement statement)Returns a  Statement: run all non-overridden@BeforeClassmethods on this class
 and superclasses before executingstatement; if any throws an
 Exception, stop execution and pass the exception on. | 
| protected org.junit.runners.model.Statement | withBefores(org.junit.runners.model.FrameworkMethod method,
           Object target,
           org.junit.runners.model.Statement statement)Deprecated. 
 Will be private soon: use Rules instead | 
| protected org.junit.runners.model.Statement | withPotentialTimeout(org.junit.runners.model.FrameworkMethod method,
                    Object test,
                    org.junit.runners.model.Statement next)Deprecated. 
 Will be private soon: use Rules instead | 
public LoadTimeWeavableTestRunner(Class<?> testClass) throws org.junit.runners.model.InitializationError
ParentRunner that will run @TestClassorg.junit.runners.model.InitializationErrorprotected ClassLoader getCustomClassLoader()
protected void validatePublicVoidNoArgMethods(Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors)
errors if any method in this class is annotated with
 annotation, but:
 isStatic is false), or
 isStatic is true).protected org.junit.runners.model.Statement classBlock(org.junit.runner.notification.RunNotifier notifier)
Statement to run all of the tests in the test class. Override to add pre-/post-processing.
 Here is an outline of the implementation:
 runChild(org.junit.runners.model.FrameworkMethod, org.junit.runner.notification.RunNotifier) on each object returned by getChildren() (subject to any imposed filter and sort).@BeforeClass methods on this class
 and superclasses before the previous step; if any throws an
 Exception, stop execution and pass the exception on.
 @AfterClass methods on this class
 and superclasses before any of the previous steps; all AfterClass methods are
 always executed: exceptions thrown by previous steps are combined, if
 necessary, with exceptions from AfterClass methods into a
 MultipleFailureException.
 Statementprotected org.junit.runners.model.Statement withBeforeClasses(org.junit.runners.model.Statement statement)
Statement: run all non-overridden @BeforeClass methods on this class
 and superclasses before executing statement; if any throws an
 Exception, stop execution and pass the exception on.protected org.junit.runners.model.Statement withAfterClasses(org.junit.runners.model.Statement statement)
Statement: run all non-overridden @AfterClass methods on this class
 and superclasses before executing statement; all AfterClass methods are
 always executed: exceptions thrown by previous steps are combined, if
 necessary, with exceptions from AfterClass methods into a
 MultipleFailureException.protected List<org.junit.rules.TestRule> classRules()
ClassRules that can transform the block that runs
         each method in the tested class.protected org.junit.runners.model.Statement childrenInvoker(org.junit.runner.notification.RunNotifier notifier)
Statement: Call runChild(org.junit.runners.model.FrameworkMethod, org.junit.runner.notification.RunNotifier)
 on each object returned by getChildren() (subject to any imposed
 filter and sort)public final org.junit.runners.model.TestClass getTestClass()
TestClass object wrapping the class to be executed.public final org.junit.runners.model.TestClass getOriginalTestClass()
protected final void runLeaf(org.junit.runners.model.Statement statement, org.junit.runner.Description description, org.junit.runner.notification.RunNotifier notifier)
Statement that represents a leaf (aka atomic) test.protected Annotation[] getRunnerAnnotations()
public org.junit.runner.Description getDescription()
getDescription in interface org.junit.runner.DescribablegetDescription in class org.junit.runner.Runnerpublic void run(org.junit.runner.notification.RunNotifier notifier)
run in class org.junit.runner.Runnerprotected boolean runBootstrapTest(org.junit.runner.notification.RunNotifier notifier, org.junit.runners.model.TestClass testClass)
public void filter(org.junit.runner.manipulation.Filter filter) throws org.junit.runner.manipulation.NoTestsRemainException
filter in interface org.junit.runner.manipulation.Filterableorg.junit.runner.manipulation.NoTestsRemainExceptionpublic void sort(org.junit.runner.manipulation.Sorter sorter)
sort in interface org.junit.runner.manipulation.Sortableprotected void runChild(org.junit.runners.model.FrameworkMethod method, org.junit.runner.notification.RunNotifier notifier)
child, which can be assumed to be
 an element of the list returned by getChildren().
 Subclasses are responsible for making sure that relevant test events are
 reported through notifierprotected org.junit.runner.Description describeChild(org.junit.runners.model.FrameworkMethod method)
Description for child, which can be assumed to
 be an element of the list returned by getChildren()protected org.junit.runner.Description describeOriginalChild(org.junit.runners.model.FrameworkMethod method)
protected List<org.junit.runners.model.FrameworkMethod> getChildren()
protected List<org.junit.runners.model.FrameworkMethod> getOriginalChildren()
protected List<org.junit.runners.model.FrameworkMethod> computeTestMethods()
@Test on this class and superclasses that
 are not overridden.protected List<org.junit.runners.model.FrameworkMethod> computeOriginalTestMethods()
protected void collectInitializationErrors(List<Throwable> errors)
errors a throwable for each problem noted with the test class (available from getTestClass()).
 Default implementation adds an error for each method annotated with
 @BeforeClass or @AfterClass that is not
 public static void with no arguments.protected void validateNoNonStaticInnerClass(List<Throwable> errors)
protected void validateConstructor(List<Throwable> errors)
errors if the test class has more than one constructor,
 or if the constructor takes parameters. Override if a subclass requires
 different validation rules.protected void validateOnlyOneConstructor(List<Throwable> errors)
errors if the test class has more than one constructor
 (do not override)protected void validateZeroArgConstructor(List<Throwable> errors)
errors if the test class's single constructor takes
 parameters (do not override)@Deprecated protected void validateInstanceMethods(List<Throwable> errors)
errors for each method annotated with @Test,
 @Before, or @After that is not a public, void instance
 method with no arguments.protected void validateFields(List<Throwable> errors)
protected void validateTestMethods(List<Throwable> errors)
errors for each method annotated with @Testthat
 is not a public, void instance method with no arguments.protected Object createTest() throws Exception
Exceptionprotected void setTestMethod(Object test, Method method) throws Exception
Method on the test case if it is MethodAwaremethod - the current method to be runtest - the test instanceExceptionprotected void setTestName(Object test, Method testMethod) throws Exception
Exceptionprotected String testName(org.junit.runners.model.FrameworkMethod method)
method for Descriptions.
 Default implementation is the method's nameprotected org.junit.runners.model.Statement methodBlock(org.junit.runners.model.FrameworkMethod method)
method passes, or throws an exception if method fails.
 Here is an outline of the default implementation:
 method on the result of createTest(), and
 throw any exceptions thrown by either operation.
 method's @Test annotation has the expecting attribute, return normally only if the previous step threw an
 exception of the correct type, and throw an exception otherwise.
 method's @Test annotation has the timeout attribute, throw an exception if the previous step takes more
 than the specified number of milliseconds.
 @Before methods on this class
 and superclasses before any of the previous steps; if any throws an
 Exception, stop execution and pass the exception on.
 @After methods on this class
 and superclasses after any of the previous steps; all After methods are
 always executed: exceptions thrown by previous steps are combined, if
 necessary, with exceptions from After methods into a
 MultipleFailureException.
 @Rule fields to modify the execution of the
 above steps. A Rule may prevent all execution of the above steps,
 or add additional behavior before and after, or modify thrown exceptions.
 For more information, see TestRule
 protected org.junit.runners.model.Statement methodInvoker(org.junit.runners.model.FrameworkMethod method, Object test)
Statement that invokes method on test@Deprecated protected org.junit.runners.model.Statement possiblyExpectingExceptions(org.junit.runners.model.FrameworkMethod method, Object test, org.junit.runners.model.Statement next)
Statement: if method's @Test annotation
 has the expecting attribute, return normally only if next
 throws an exception of the correct type, and throw an exception
 otherwise.@Deprecated protected org.junit.runners.model.Statement withPotentialTimeout(org.junit.runners.model.FrameworkMethod method, Object test, org.junit.runners.model.Statement next)
Statement: if method's @Test annotation
 has the timeout attribute, throw an exception if next
 takes more than the specified number of milliseconds.@Deprecated protected org.junit.runners.model.Statement withBefores(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement)
Statement: run all non-overridden @Before
 methods on this class and superclasses before running next; if
 any throws an Exception, stop execution and pass the exception on.@Deprecated protected org.junit.runners.model.Statement withAfters(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement)
Statement: run all non-overridden @After
 methods on this class and superclasses before running next; all
 After methods are always executed: exceptions thrown by previous steps
 are combined, if necessary, with exceptions from After methods into a
 MultipleFailureException.protected List<org.junit.rules.MethodRule> rules(Object target)
target - the test case instanceprotected List<org.junit.rules.TestRule> getTestRules(Object target)
target - the test case instanceCopyright © 2005–2016 The Kuali Foundation. All rights reserved.