title: Spring configuration for embedded H2 database for tests
body: <p>What does your Spring configuration for integration tests look like using an <a href="http://www.h2database.com/html/main.html" rel="noreferrer">embedded h2 datasource</a> and, optionally, JUnit?</p>
  
  <p>My first try with a <a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/jdbc/datasource/SingleConnectionDataSource.html" rel="noreferrer">SingleConnectionDataSource</a> basically worked, but failed on more complicated tests where you need several connections at the same time or suspended transactions. I think h2 in <a href="https://stackoverflow.com/questions/1503079/start-the-h2-database-in-server-mode-via-spring">tcp based server mode</a> might work as well, but this is probably not the fastest communication mode for a temporary embedded database in memory.</p>
  
  <p>What are the possibilities and their advantages / disadvantages? Also, how do you create the tables / populate the database?</p>
  
  <hr>
  
  <p>Update: Let's specify some concrete requirements that are important for such tests.</p>
  
  <ul>
  <li>The database should be temporary and in memory</li>
  <li>The connection should probably not use tcp, for speed requirements</li>
  <li>It would be nice if I could use a database tool to inspect the content of the database during debugging</li>
  <li>We have to define a datasource since we can't use the application servers datasource in unit tests</li>
  </ul>