title: Run unit test independently without involving spring
body: <p>I have application written in <code>spring boot</code>.
  I am using <code>testNG</code> and <code>mockito</code> for unit testing.</p>
  
  <p>I am bit confuse with working of unit tests.</p>
  
  <p>Following is my test class</p>
  
  <pre><code>class StudentServiceTest {
      @mock
      StudentDAO studentDAO;
  
      @InjectMocks
      StudentService studentService;
  
      @BeforeMethod
      public void initMock() {
          studentService = new StudentService();
          MockitoAnnotations.initMocks(this);
      }
  
      @Test(dataprovider.....)
      public void shouldxxxxx(int id......) {
         when(studentDAO.findOne(id)).thenReturn(Student);
         assert......
      }
  }
  </code></pre>
  
  <p>When I run above test. It works fine.</p>
  
  <p>I have following doubts.</p>
  
  <ol>
  <li>Does it involves spring. If not then how @mock and other code works</li>
  <li>Should we involve spring.If not/yes why?</li>
  <li>I have used <strong>new</strong> key word to initialize service. Is it good. 
  As in <a href="http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html" rel="nofollow">spring unit test documentation</a> they have said that</li>
  </ol>
  
  <blockquote>
    <p>You can simply instantiate objects using the new operator without even involving Spring. You can also use mock objects instead of real dependencies</p>
  </blockquote>
  
  <p>If I not instantiate service with new keyword then it show error <strong>"Cannot instantiate @InjectMocks</strong>".</p>
  
  <p>If I <code>autowired</code> service then it requires spring container and it I run even single test, it takes too much time to run. And If <code>not autowired</code> and use <code>new</code> keyword then it runs very fast.</p>
  
  <ol start="4">
  <li>Does above code is clean? Please do suggest best practice to write unit test in spring boot with testNg and mockito.</li>
  </ol>