[Beankeeper-discussion] newbie using in memory hsql for unit tests and failing
Brought to you by:
demonsystem
From: Emily G. <emi...@go...> - 2009-06-11 11:03:07
|
Hi, I'm new to Beankeeper. It's looks absolutely perfect for the thing I'm currently working on at the mo that's got enough database use to be too annoying to program directly, but not enough to make something a bit more bloated like Hibernate seem worthwhile (goodness I loathe those XML files!). Anyhow, I have a quick question - I'm probably doing some sort of newbie daft thing. When I write unit tests I normally use an in memory HSQL database, but I'm finding that when I do this through Beankeeper the database isn't shutdown and recreated properly between tests. I've written a hopefully simple example to show what I mean. What happens is that each of the two tests run fine on their own, but when ran together the results of the first test are left in the database causing the second test to fail as it finds two records rather than the expected one. Hope I'm not being too annoying!! Thanks, Emily /** * Record object I'm going to be using in the test */ public class Record { private String value; public Record() { super(); } public void setValue(String value) { this.value = value; } public String getValue() { return value; } } /** * My failing unit test */ public class SimpleTest extends TestCase { private Store store; protected void setUp() throws Exception { store = new Store("org.hsqldb.jdbc.Driver", "jdbc:hsqldb:mem:test"); } protected void tearDown() throws Exception { store.close(); } public void testSavingARecord() { Record record = new Record(); record.setValue("bob"); store.save(record); List<Record> savedRecords = store.find("find record"); assertEquals(1, savedRecords.size()); Record firstSavedRecord = savedRecords.get(0); assertEquals("bob", firstSavedRecord.getValue()); } public void testSavingAnotherRecord() { Record record = new Record(); record.setValue("sue"); store.save(record); List<Record> savedRecords = store.find("find record"); assertEquals(1, savedRecords.size()); Record firstSavedRecord = savedRecords.get(0); assertEquals("sue", firstSavedRecord.getValue()); } } |