Thursday, October 30, 2008
Debugging DBUnit
Today was more debugging of DBUnit bugs that was still plaguing our test cases. At first we thought the problem was that Hibernate was not creating the DB schema before DBUnit could load the database. So we tried opening/creating a session in the constructor of the testcase before dbunit loaded the sample.xml file into the HSQLDB. This, still produced errors about tables not being found. Eventually, after many attempts on changing the configuration of both Hibernate and DBUnit, we realized that DBUnit did not recognize it's own XML file it created from its Maven2 plugin incarnation. This makes utterly no sense and was unfathomable as to why it would create incompatible formats of XML files for backup. This seemed to be the root of the problem, even though the hunch of having to open a Hibernate session in the TestCase's constructor was still correct since DBUnit does not store the table's schema inside it's XML backups. Since the backup from the Maven2 dbunit plugin no longer worked, we had to first re-import the sample dataset into the server using the maven dbunit plugin, write a function (it's in a Main class right now) to export the database programmatically using the dbunit JAR (and its myriad of dependencies). Now that the JUnit tests work, we plan to encapsulate the quirks of the JUnit into its own subclass so we don't have to write boiler plate cold for each test file. Our test cases can use dbunit functions to compare the manipulated DB and the resulting DB as well as all the standard JUnit asserts.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment