title: Using MockitoJUnitRunner.class instead of SpringJUnit4ClassRunner.class
body: <p>I have a question about the usage of <code>SpringJUnit4ClassRunner</code>. For pure Junits or Unit Test cases should we use Spring based annotations such as <code>@Autowired</code> along with <code>SpringJUnit4ClassRunner</code> or should we use only the <code>MockitoJUnitRunner</code> instead with the <code>@RunWith</code> annotation at the top of the Test class?</p>
  
  <p>I mean replacing</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration({ "classpath:test-applicationContext.xml" })
  </code></pre>
  
  <p>with just</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  </code></pre>
  
  <p>at the top of the class. It works for me.</p>
  
  <p>In Junits we normally do not make any external calls such as calls to DB or call to some other web service. We have to mock these external calls using <code>@Mock</code> annotations on this service objects. And then create a real object of the class that we are testing and that depends on these mocks. We can then use <code>@InjectMocks</code> on the real object so that it will be injected with the mocked objects.</p>
  
  <p>Example Service-A->Calls->Service-B->Calls->Service-C</p>
  
  <p>While testing A we should mock Service B &amp; while testing Service-B we should mock Service-C.</p>
  
  <p>Some code Snippet </p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class TestServiceA {
      @Mock
      B mockObj;
  
      @InjectMocks
      A realObj;
  
      @Test
      public void testServiceA() {
      .....
      .....
      }
  }       
  </code></pre>
  
  <p>So, I feel for Unit test cases we need not rely on Spring container to provide us the instance of the class we are testing.</p>
  
  <p>Please give your suggestions.</p>
  
  <p>Using SpringJUnit4ClassRunner.class instead of MockitoJUnitRunner.class</p>