org.xwiki.test.isolation
Class IsolatedTestRunner

java.lang.Object
  extended by org.junit.runner.Runner
      extended by org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
          extended by org.junit.runners.BlockJUnit4ClassRunner
              extended by org.xwiki.test.isolation.IsolatedTestRunner
All Implemented Interfaces:
org.junit.runner.Describable, org.junit.runner.manipulation.Filterable, org.junit.runner.manipulation.Sortable

public class IsolatedTestRunner
extends org.junit.runners.BlockJUnit4ClassRunner

Specialized JUnit4 runner to isolate some classes during the execution of a test class. This runner should be used in combination with the IsolatedClassPrefix annotation. Isolation is helpful when you do not want to pollute the application ClassLoader with some classes under test, or some dynamically loaded classes during a test. It could be used to reinitialize statics and drop out those dynamically loaded classes after the test. To use this class, define a JUnit @RunWith annotation on your test class and also add a IsolatedClassPrefix annotation to define the list of class prefixes that should be isolated from the rest of your tests. For example:

 @RunWith(IsolatedTestRunner)
 @IsolatedClassPrefix("org.xwiki.mypackage")
 public class MyPackageTest
 {
     @Test
     public void someTest() throws Exception
     {
     ...
 }
 
The prefixes should at least include a prefix that match your test class, else the initialization will fail, since your test would not be run in isolation properly. If you are mocking some of your isolated classes with Mockito in different tests (either isolated or not), you will need to disable the class cache used by Mockito to avoid ClassCastException during mocking. You can disable the cache by adding the following class to your test Jar :
 package org.mockito.configuration;
 public class MockitoConfiguration extends DefaultMockitoConfiguration
 {
     @Override
     public boolean enableClassCache()
     {
         return false;
     }
 }
 

Since:
5.0M2
Version:
$Id: 3c560d1eda7b892700a2e1e8be4670636c7d710f $

Constructor Summary
IsolatedTestRunner(Class<?> clazz)
          Creates a BlockJUnit4ClassRunner to run clazz.
 
Method Summary
 
Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner
collectInitializationErrors, computeTestMethods, createTest, describeChild, getChildren, getTestRules, 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, 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
 

Constructor Detail

IsolatedTestRunner

public IsolatedTestRunner(Class<?> clazz)
                   throws org.junit.runners.model.InitializationError
Creates a BlockJUnit4ClassRunner to run clazz.

Parameters:
clazz - the test class to be run in isolation
Throws:
org.junit.runners.model.InitializationError - if the test class is malformed.


Copyright © 2004–2014 XWiki. All rights reserved.