Open peidong-hu opened 9 years ago
for example, code could be placed here, https://github.com/bigtester/automation-test-engine/blob/master/org.bigtester.ate.core/src/main/java/org/bigtester/ate/TestProjectRunner.java#L105
Could I tearDown the database before Initializer dbinit? So I added some code in TestDatabaseInitializer file:
/** Teardown the database before Initialize.
*/
protected @Nullable DatabaseOperation getTearDownOperation()
throws DatabaseUnitException, SQLException, MalformedURLException {
return DatabaseOperation.NONE;}
Yes, it is a good idea to use the dbunit embeded feature to teardown db. I just see there is a teardown annotation in dbunit.
But you need to check if this annotation will remove the schema or not. We want to remove not only the data rows in db, but also the schema before launching test. On May 24, 2015 12:07 AM, "ericlu312" notifications@github.com wrote:
Could I tearDown the database before Initializer dbinit? So I added some code in TestDatabaseInitializer file:
/** Teardown the database before Initialize.
*/ protected @Nullable DatabaseOperation getTearDownOperation() throws DatabaseUnitException, SQLException, MalformedURLException { return DatabaseOperation.NONE;}
— Reply to this email directly or view it on GitHub https://github.com/bigtester/automation-test-engine/issues/121#issuecomment-104977237 .
At last, So I added some code in TestDatabaseInitializer:
public class TestDatabaseInitializer {
/**
Teardown the database before Initialize.
*/
public void TearDownDatabase(ApplicationContext context)
throws DatabaseUnitException, SQLException, MalformedURLException {
if (getInitXmlFiles().isEmpty()) {DatabaseOperation.DELETE.execute(null, null ); }
}
DatabaseOperation.DELETE.execute: This operation deletes only the dataset contents from the database. This operation does not delete the entire table contents but only data that are present in the dataset.
We will need to delete the table completely.
Peidong
On 05/27/2015 10:18 PM, ericlu312 wrote:
At last, So I added some code in TestDatabaseInitializer:
|public class TestDatabaseInitializer {
/** Teardown the database before Initialize.
*/ public void TearDownDatabase(ApplicationContext context) throws DatabaseUnitException, SQLException, MalformedURLException { if (getInitXmlFiles().isEmpty()) {DatabaseOperation.DELETE.execute(null, null ); } } DatabaseOperation.DELETE.execute: This operation deletes only the dataset contents from the database. This operation does not delete the entire table contents but only data that are present in the dataset. |
— Reply to this email directly or view it on GitHub https://github.com/bigtester/automation-test-engine/issues/121#issuecomment-106149008.
I changed the code like this:
public void TearDownDatabase(ApplicationContext context) throws DatabaseUnitException, SQLException, MalformedURLException { try{ DataSource datas = GlobalUtils.findDataSourceBean(context); IDatabaseConnection con = new DatabaseConnection(datas.getConnection());
DatabaseOperation.CLEAN_INSERT.execute(null, null );
con.close();
}
catch(DatabaseUnitException | SQLException e){}
}
It looks good to me. But to validate if this works well, you can open up the files in the data/ folder to see if it works as we expect. there are logs of dbunit execution under data/ folder.
Peidong
On 05/28/2015 11:40 PM, ericlu312 wrote:
I changed the code like this:
public void TearDownDatabase(ApplicationContext context) throws DatabaseUnitException, SQLException, MalformedURLException { try{ DataSource datas = GlobalUtils.findDataSourceBean(context); IDatabaseConnection con = new DatabaseConnection(datas.getConnection());
DatabaseOperation.CLEAN_INSERT.execute(null, null ); con.close(); } catch(DatabaseUnitException SQLException e){} } — Reply to this email directly or view it on GitHub https://github.com/bigtester/automation-test-engine/issues/121#issuecomment-106673600.
Jun, can u help to f8nish the work of this issue. You had encountered it before the holiday.
data folder legacy data will causes the failure of dbunit to create and loading data. We need to add code to clean up this folder at the beginning of the program.