views:

133

answers:

1

I am using DBUnit to test a Spring/Hibernate persistence.

I created an abstract test:

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);
  }
 }
}

But whenever I run a test, it refresh the DB agains the dataSet before EVERY test method, which is quite very long and very not nice I think.

How could I reload/refresh only on failure?

P.S.: How much does the code suck?

A: 

I found a way to speed up the tests, even thought the behaviour is still not as expected (refresh on fail):

 dbUnitConConfig.setFeature(DatabaseConfig.FEATURE_BATCHED_STATEMENTS,
   true);
brisssou