title: Best Practice Changing Spring Implementation Object in JUnit Test
body: <p>I have a Spring-enabled JUnit Test. It loads my default applicationContext.
  Now I want to replace a single bean for my test, i.e. entityManager with testEntityManager.</p>
  
  <p>I can imagine three possible ways, which don't seem very elegant:</p>
  
  <ol>
  <li>split the context (defaultContext, emContext) and override context file by test context file (emContext in test resources)</li>
  <li>use factory and choose testEntityManager (in production code)</li>
  <li>not to use Spring, but build the object hierarchy myself (least feasible solution)</li>
  </ol>
  
  <p>Is there a best practice how to do it <em>right</em>?</p>
  
  <p>Background to this question is: I really only want to replace the objects close at the boundary (DB, Webservices, etc)</p>
  
  <p>Yours Sincerely</p>
  
  <p><strong>EDIT: I have solved it this way now:
  I added a properties file to my classpath and test classpath and used a Spring alias in conjunction with a property placeholder.
  This way I was able to wire my beans to a different implementation in the tests.</strong></p>