title: Changing Database schemas & unit tests
body: <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Before we start I know a fair few people consider tests that hit the database not "unit tests". Maybe "integration tests" would be a better name. Either way developer tests that hit the database.</p>
  
  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To enable unit-testing I have a developer local database which I clear and the populate with a know set of data at the start of each test using <a href="http://www.dbunit.org/" rel="noreferrer">dbUnit</a>. This all works well enough until a table used by the test changes in some way and I have to manually update all the XML datasets. Which is a pain. I figure other people must have hit the same problem and hopefully found a nice neat solution to it. So for tests that require populating a database what do you use and how do you handle table definitions changing? (While I use Java I am open to solutions utilizing different technologies.)</p>
  
  <p><strong>EDIT:</strong>
  To clarify a little. I have a contrived test like:</p>
  
  <pre><code>void testLoadRevision() {
      database.clear(); // Clears every table dbUnit knows about.
      database.load("load/trevision.xml", "load/tissue.xml");
      SomeDatabaseThingie subject = new SomeDatabaseThingie(databaseProvider);
      Revision actual = subject.load();
      assert(actual, expected);
  }
  </code></pre>
  
  <p>In that I have two tables - tRevision and tIssue. A loaded revision uses a small amount of data from tIssue. Later on tIssue acquires a new field that revisions do not care about. As the new field is "not null" and has no sensible default this test it will fail as the tIssue.xml will be invalid. </p>
  
  <p>With small changes like this it is not too hard to edit the tIssue. But when the number of XML files starts to balloon with each flow it becomes a large amount of work.</p>
  
  <p>Cheers,<br>
  &nbsp;&nbsp;&nbsp;&nbsp;mlk</p>