org.mockito.runners
Class MockitoJUnit44Runner

java.lang.Object
  extended by org.junit.runner.Runner
      extended by org.junit.internal.runners.JUnit4ClassRunner
          extended by org.mockito.runners.MockitoJUnit44Runner
All Implemented Interfaces:
org.junit.runner.Describable, org.junit.runner.manipulation.Filterable, org.junit.runner.manipulation.Sortable

public class MockitoJUnit44Runner
extends org.junit.internal.runners.JUnit4ClassRunner

JUnit 4.4 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
MockitoJUnit44Runner(java.lang.Class<?> klass)
           
 
Method Summary
protected  java.lang.Object createTest()
           
 
Methods inherited from class org.junit.internal.runners.JUnit4ClassRunner
classAnnotations, filter, getDescription, getName, getTestClass, getTestMethods, invokeTestMethod, methodDescription, run, runMethods, sort, testAnnotations, testName, validate, wrapMethod
 
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

MockitoJUnit44Runner

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

createTest

protected java.lang.Object createTest()
                               throws java.lang.Exception
Overrides:
createTest in class org.junit.internal.runners.JUnit4ClassRunner
Throws:
java.lang.Exception