Why not do the same thing you do in a JDBC environment just using OJB? It's actually easier in my opinion to use OJB in this capacity than it is to use straight JDBC.
Here's my setup: My "test" target in my build.xml depends on a "clean-test-db" target. The "clean-test-db" target runs an "sql" task that loads an SQL file that drops all of the tables (including the OJB tables) and the rebuilds the database from scratch. So when the "test" target runs, it always has an empty database to work with. In my junit testcases, I use OJB in setUp() and tearDown() to create any necessary data and then remove it after a testcase has run. If setting up the data becomes programmatically prohibitive in the future, then I'll probably just create the data once and dump it into an SQL file that can then be loaded by ant before the required test(s). This all works pretty well for me so far, but admittedly I just started using OJB so we'll see if I run into any problems. Hope this helps, -Brian ----- Original Message ----- From: "Bryan Dollery" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Thursday, September 26, 2002 12:11 PM Subject: Unit-Testing? > Hi, > > Does anyone else write unit-tests? > > I'm trying to unit-test my code, and it's hard. > > In a normal JDBC environment, using JUnit, I'd setup a database in the > setUp() method, and delete the mess I'd made of it in the tearDown() > method. > > With an O/R mapping layer between me and the database I can't just play > with the data - it isn't mine any more. I can't just add or delete a record > from a table because there may be things I don't know about - index tables, > references, whatever - and if there isn't now, there may be in the future. > The point of having an O/R tool is to encapsulate the DB, the downside is > that this makes it difficult to test. > > So, what does everyone else do for their testing? > > Cheers, > > Bryan > > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
