org.mockito.runners
Class MockitoJUnitRunner

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.mockito.runners.MockitoJUnitRunner
All Implemented Interfaces:
org.junit.runner.Describable, org.junit.runner.manipulation.Filterable, org.junit.runner.manipulation.Sortable
Direct Known Subclasses:
VerboseMockitoJUnitRunner

public class MockitoJUnitRunner
extends org.junit.runners.BlockJUnit4ClassRunner

Uses JUnit 4.5 runner BlockJUnit4ClassRunner.

JUnit 4.5 runner initializes mocks annotated with Mock, so that explicit usage of MockitoAnnotations.initMocks(Object) is not necessary. Mocks are initialized before each test method.

Runner is completely optional - there are other ways you can get @Mock working, for example by writing a base class.

Read more in javadoc for MockitoAnnotations

Example:

 @RunWith(MockitoJUnit44Runner.class)
 public class ExampleTest {
 
     @Mock
     private List list;
 
     @Test
     public void shouldDoSomething() {
         list.add(100);
     }
 }
 


Constructor Summary
MockitoJUnitRunner(java.lang.Class<?> klass)
           
 
Method Summary
protected  org.junit.runners.model.Statement withBefores(org.junit.runners.model.FrameworkMethod method, java.lang.Object target, org.junit.runners.model.Statement statement)
           
 
Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner
collectInitializationErrors, computeTestMethods, createTest, describeChild, getChildren, methodBlock, methodInvoker, possiblyExpectingExceptions, runChild, testName, validateInstanceMethods, validateTestMethods, validateZeroArgConstructor, withAfters, withPotentialTimeout
 
Methods inherited from class org.junit.runners.ParentRunner
childrenInvoker, classBlock, filter, getDescription, getName, getTestClass, run, 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
 
Methods inherited from interface org.junit.runner.manipulation.Filterable
filter
 
Methods inherited from interface org.junit.runner.manipulation.Sortable
sort
 

Constructor Detail

MockitoJUnitRunner

public MockitoJUnitRunner(java.lang.Class<?> klass)
                   throws org.junit.runners.model.InitializationError
Throws:
org.junit.runners.model.InitializationError
Method Detail

withBefores

protected org.junit.runners.model.Statement withBefores(org.junit.runners.model.FrameworkMethod method,
                                                        java.lang.Object target,
                                                        org.junit.runners.model.Statement statement)
Overrides:
withBefores in class org.junit.runners.BlockJUnit4ClassRunner