Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright (c) 2007 Mockito contributors
  * This program is made available under the terms of the MIT License.
 package org.mockito.runners;
 import  org.junit.runner.Description;
 import  org.junit.runner.Runner;
 import  org.junit.runner.notification.RunNotifier;
Compatible with JUnit 4.4 and higher, this runner adds following behavior:
  • Initializes mocks annotated with Mock, so that explicit usage of MockitoAnnotations.initMocks(Object) is not necessary. Mocks are initialized before each test method.
  • validates framework usage after each test method. See javadoc for Mockito.validateMockitoUsage().
Runner is completely optional - there are other ways you can get @Mock working, for example by writing a base class. Explicitly validating framework usage is also optional because it is triggered automatically by Mockito every time you use the framework. See javadoc for Mockito.validateMockitoUsage().

Read more about @Mock annotation in javadoc for MockitoAnnotations

 public class ExampleTest {
     private List list;
     public void shouldDoSomething() {
public class MockitoJUnitRunner extends Runner {
    private final RunnerImpl runner;
    public MockitoJUnitRunner(Class<?> klassthrows InvocationTargetException {
         = new RunnerFactory().create(klass);
    public void run(final RunNotifier notifier) {           
    public Description getDescription() {
        return .getDescription();
New to GrepCode? Check out our FAQ X