title: unit testing EJB 3.1 - why mock container services
body: <p>What is the advantage of mocking the container services in Unit testing of EJB 3.1?</p>
  
  <p>The probable answers I get when I think about it are,</p>
  
  <ol>
  <li>It improves the performance of the tests.</li>
  <li>It does not abide by the rules of Unit testing as there is a lot of interactions with other APIs. <em>(Please provide your views on this)</em></li>
  </ol>
  
  <p>Other than these, do you think there are other advantages?   </p>
  
  <p>As many of you may know, it is possible to test some of the services provided by the container, like persistence, transaction management (eg. using Bitronix), messaging (eg. using Apache ActiveMQ and in-memory JNDI) out of the container in your own JVM.  Still there is an argument that it is integration testing and unit testing should not be done that way.</p>
  
  <p>According to me, if you can have a good performance in your tests, it is fine to use these third party implementations for unit testing because you do not have to spend too much time in mocking and mocking is heavily subject to developer errors.  If a developer does not have a good understanding of mocking, he might end up mocking everything or in other words misusing mocking to turn the tests "green".  Is this right?  <em>(Please provide your views on this)</em></p>
  
  <p>After all, I never got any solid definition of unit testing :-).  It depends on the author.  Some define "unit" as the smallest unit that can be tested and some define "Depending on the context, these could be the individual subprograms or a larger component made of tightly related units."</p>
  
  <p>Thanks.</p>