我正在使用 DBUnit 来测试 Spring/Hibernate 持久性。
我创建了一个抽象测试:
public abstract class AbstractTestCase extends
AbstractTransactionalDataSourceSpringContextTests {
@Override
protected String[] getConfigLocations() {
return new String[] {
"classpath:/applicationContext.xml",
"classpath:/testDataSource.xml" };
}
@Override
protected void onSetUpInTransaction() throws Exception {
DataSource dataSource = jdbcTemplate.getDataSource();
Connection con = DataSourceUtils.getConnection(dataSource);
boolean validateSchemaExists = true;
IDatabaseConnection dbUnitCon = new DatabaseConnection(con,
"MHADB_TEST", validateSchemaExists);
DatabaseConfig dbUnitConConfig = dbUnitCon.getConfig();
dbUnitConConfig.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
new OracleDataTypeFactory());
boolean enableColumnSensing = true;
boolean enableDTDMetadata = false;
IDataSet dataSet = new FlatXmlDataSet(new File(
"./src/test/resources/mhadb-dataset.xml"),
enableDTDMetadata,
enableColumnSensing);
try {
DatabaseOperation.CLEAN_INSERT.execute(dbUnitCon, dataSet);
} finally {
DataSourceUtils.releaseConnection(con, dataSource);
}
}
}
但是每当我运行测试时,它会在每个测试方法之前再次刷新数据库,这很长而且我认为这不是很好。
我怎样才能仅在失败时重新加载/刷新?
PS:代码有多烂?