title: DAO layer testing strategy with JUnit and Spring
body: <p>I'm trying to devise an optimal strategy to unit-test DAO layer of my Spring app.
  Many existing approaches like in-memory DB usage, etc (posts: 12289800, 12390813, 9940010, 12801926). do not appeal to me.</p>
  
  <p>So, here is a straightforward way that occurs to me:</p>
  
  <ol>
  <li>Create Spring test-context.xml and put there all the data needed for testing all the DAO classes;</li>
  <li>For each test class create a template method to test CRUD operations and all 'select' operations;</li>
  <li>Before testing, insert all needed data from test-context.xml to your real DB. We may need also some dependencies (references), so insert them as well, let's say in @Before method.</li>
  <li>After all CRUD operations, delete all dependencies (references) from DB, let's say in @After method.</li>
  </ol>
  
  <p>If we have a lot of dependencies, this may become a terribly expensive and laborious approach. Also we have only one @Test method (template method, to ensure the order of operations: create, read... etc.) - so one test per test class.</p>
  
  <p>So, I need an advice whether this strategy is viable? What similar did you do to test your DAOs?</p>