【发布时间】:2012-01-17 08:02:41
【问题描述】:
我有大约 10 个 JUnit 将自动执行。我想在每个人中重置数据库。我有这段代码:
//@Transactional
public class TestMediaObjectService extends AbstractDataAccessTest{
//This method reset the database, emptying the tables
@Test
public void testCreateDataBase() throws Exception {
TestDatabaseCreation creation = new TestDatabaseCreation();
creation.resetDatabase();
}
//This is one of the methods.
@Test
public void testStoreMediaObject() throws Exception {
//......
}
当我使用我在方法testCreateDataBase 中使用的相同脚本手动重置数据库,然后运行此测试(不使用该方法)时,会自动创建表。但是,如果我按照上面粘贴的方式运行代码,则不会创建该表,因此会出现此错误:
原因:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:表“one_table”不存在
在测试中运行其他方法之前,我怎样才能在 every 中运行该方法?注解@Transactional被移除了,但是错误依旧存在。
【问题讨论】:
标签: mysql hibernate spring junit