I have a problem when I tried to test my class with the database. I am not using hibernate so I cannot rollback database. When exception occurs the database operation stops the test for the exception passes but it fails other test I wrote. How can I prevent this?
@RunWith(SpringJunit4ClassRunne.class)
@ContextConfiguration("test.xml")
public class MachineDaoTest{
@Autowired
private DataSource ds;
@Before
public void setUp(){...}
@Test
public void testFindVersion(){
....
}
@Test
public void testException() {
try {
someMethod.getVersion("xxyyzz");
fail("Expected DB Exception");
} catch (Exception e) {
assertTrue(e instanceof DbException);
}
Now in xml file I have included two sql file. One create tables and set values and another one that drop tables and cause exception. Since the database was autowired how am I able to rollback or make both test pass?
Aucun commentaire:
Enregistrer un commentaire