com.google.gwtmockito
Class GwtMockitoTestRunner

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 com.google.gwtmockito.GwtMockitoTestRunner
All Implemented Interfaces:
Describable, Filterable, Sortable

public class GwtMockitoTestRunner
extends BlockJUnit4ClassRunner

A JUnit4 test runner that executes a test using GwtMockito. In addition to the standard BlockJUnit4ClassRunner features, a test executed with GwtMockitoTestRunner will behave as follows:

Author:
ekuefler@google.com (Erik Kuefler)
See Also:
GwtMockito

Constructor Summary
GwtMockitoTestRunner(Class<?> unitTestClass)
          Creates a test runner which allows final GWT classes to be mocked.
 
Method Summary
protected  List<String> getAdditionalClasspaths()
          Returns a list of additional sources from which the classloader should read while running tests.
protected  Collection<Class<?>> getClassesToStub()
          Returns a collection of classes whose non-abstract methods should always be replaced with no-ops.
protected  ClassLoader getParentClassloader()
          Returns the classloader to use as the parent of GwtMockito's classloader.
 void run(RunNotifier notifier)
          Runs the tests in this runner, ensuring that the custom GwtMockito classloader is installed as the context classloader.
protected  org.junit.runners.model.Statement withBefores(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement)
          Overridden to invoke GwtMockito.initMocks before starting each test.
 
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, withPotentialTimeout
 
Methods inherited from class org.junit.runners.ParentRunner
childrenInvoker, classBlock, classRules, filter, getDescription, getName, getRunnerAnnotations, getTestClass, 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

GwtMockitoTestRunner

public GwtMockitoTestRunner(Class<?> unitTestClass)
                     throws org.junit.runners.model.InitializationError
Creates a test runner which allows final GWT classes to be mocked. Works by reloading the test class using a custom classloader and substituting the reference.

Throws:
org.junit.runners.model.InitializationError
Method Detail

getClassesToStub

protected Collection<Class<?>> getClassesToStub()
Returns a collection of classes whose non-abstract methods should always be replaced with no-ops. By default, this list includes Composite, DOM UIObject, Widget, and most subclasses of Panel. This makes it much safer to test code that uses or extends these types.

This list can be customized by defining a new test runner extending GwtMockitoTestRunner and overriding this method. This allows users to explicitly stub out particular classes that are causing problems in tests. If you do this, you will probably want to retain the classes that are stubbed here by doing something like this:

 @Override
 protected Collection<Class<?>> getClassesToStub() {
   Collection<Class<?>> classes = super.getClassesToStub();
   classes.add(MyBaseWidget.class);
   return classes;
 }
 

Returns:
a collection of classes whose methods should be stubbed with no-ops while running tests

getParentClassloader

protected ClassLoader getParentClassloader()
Returns the classloader to use as the parent of GwtMockito's classloader. By default this is the system classloader. This can be customized by defining a custom test runner extending GwtMockitoTestRunner and overriding this method.

Returns:
classloader to use for delegation when loading classes via GwtMockito

getAdditionalClasspaths

protected List<String> getAdditionalClasspaths()
Returns a list of additional sources from which the classloader should read while running tests. By default this list is empty; custom sources can be specified by defining a custom test runner extending GwtMockitoTestRunner and overriding this method.

The entries in this list must be paths referencing a directory, jar, or zip file. The entries must not end with a "/". If an entry ends with "/*", then all jars matching the path name are included.

Returns:
a list of strings to be appended to the classpath used when running tests
See Also:
ClassPool.appendClassPath(String)

run

public void run(RunNotifier notifier)
Runs the tests in this runner, ensuring that the custom GwtMockito classloader is installed as the context classloader.

Overrides:
run in class ParentRunner<org.junit.runners.model.FrameworkMethod>

withBefores

protected final org.junit.runners.model.Statement withBefores(org.junit.runners.model.FrameworkMethod method,
                                                              Object target,
                                                              org.junit.runners.model.Statement statement)
Overridden to invoke GwtMockito.initMocks before starting each test.

Overrides:
withBefores in class BlockJUnit4ClassRunner


Copyright © 2013. All Rights Reserved.