|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Transaction management in DBUnitHi,
I have worked with DbUnit and I think it is the best tool to for db tests. I have an issue I hope DbUnit addresses this issue. In my project, we use Callable Statements to make CRUD calls. Some of the calls are complex package calls. To test crud operations, what we would like to do is 1. invoke a CRUD call (Create) and committed 2. Test if data exists 3. After the test has been executed, roll back all changes automatically unconditionally (when the test passes, fails or if an exception is thrown). From what I understand is that DatabaseOperation.INSERT should followed by DatabaseOperation.DELETE which are two separate operations but should be transactional. What I would prefer is that the changes were rolled back instead of calling delete. Because a successful insert may involve different tables with different constraints, it is very difficult for us to delete multiple entries from different tables. Is there a facility for this purpose? Thanks, Kartik ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ dbunit-user mailing list dbunit-user@... https://lists.sourceforge.net/lists/listinfo/dbunit-user |
|
|
|
|
|
Re: Transaction management in DBUnitMatthias,
I looked through some source code. I missed this feature. Let me look into it and I will let you know how this works. Perhaps, I could leverage this feature to manage transactions outside of testing environment. Thanks, Karthik On Fri, Jul 31, 2009 at 1:08 PM, Matthias Gommeringer <Matthias.Gommeringer@...> wrote: Hi there, ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ dbunit-user mailing list dbunit-user@... https://lists.sourceforge.net/lists/listinfo/dbunit-user |
|
|
|
|
|
Re: Transaction management in DBUnitI've tried to do something similar, but it turn out having very very
slow test. Instead, turn off transaction in test case and just delete everything before next test case work better for me, btw, it was tested in oracle, sybase and sql server, all have similar behavior. On Fri, Jul 31, 2009 at 8:00 AM, Karthik Krishnan<krishnan.1000@...> wrote: > Hi, > > I have worked with DbUnit and I think it is the best tool to for db tests. I > have an issue I hope DbUnit addresses this issue. In my project, we use > Callable Statements to make CRUD calls. Some of the calls are complex > package calls. To test crud operations, what we would like to do is > > 1. invoke a CRUD call (Create) and committed > 2. Test if data exists > 3. After the test has been executed, roll back all changes automatically > unconditionally (when the test passes, fails or if an exception is thrown). > From what I understand is that DatabaseOperation.INSERT should followed by > DatabaseOperation.DELETE which are two separate operations but should be > transactional. What I would prefer is that the changes were rolled back > instead of calling delete. Because a successful insert may involve different > tables with different constraints, it is very difficult for us to delete > multiple entries from different tables. > > Is there a facility for this purpose? > > Thanks, > > Kartik > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus > on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > dbunit-user mailing list > dbunit-user@... > https://lists.sourceforge.net/lists/listinfo/dbunit-user > > ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ dbunit-user mailing list dbunit-user@... https://lists.sourceforge.net/lists/listinfo/dbunit-user |
|
|
Re: Transaction management in DBUnitHi Carfield,
Thanks for your update. I believe that Spring's testing framework has something like this but I have not investigated it. There does not seem to be a direct way to hook onto to DbUnit with Spring, but let me look into it. Thanks, Kartik On Sat, Aug 1, 2009 at 8:13 AM, Carfield Yim <carfield@...> wrote: I've tried to do something similar, but it turn out having very very ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ dbunit-user mailing list dbunit-user@... https://lists.sourceforge.net/lists/listinfo/dbunit-user |
|
|
Re: Transaction management in DBUnitSpring does have a very good mechanism for this called
AbstractTransactionalDataSourceSpringContextTests Here is an example project I set up that uses it: http://zenoconsulting.wikidot.com/blog:8 I'm following a very similar pattern in a new project but not using Hibernate or JPA -- just pure Spring JdbcTemplate. Make an AbstractDbUnitTestCase something like this: public abstract class AbstractDbUnitTestCase extends AbstractTransactionalDataSourceSpringContextTests { protected Object classUnderTest; /** * Constructor */ public AbstractDbUnitTestCase() { ApplicationContext ctx = super.getApplicationContext(); classUnderTest = ctx.getBean(getBeanName()); assertNotNull(classUnderTest); } /** * (non-Javadoc) * @see org.springframework.test.AbstractSingleSpringContextTests#getConfigLocations() */ @Override protected String[] getConfigLocations() { return new String[] { "classpath:applicationContext.xml" }; } /** * (non-Javadoc) * @see org.springframework.test.AbstractTransactionalSpringContextTests#onSetUpInTransaction() */ @Override protected void onSetUpInTransaction() throws Exception { DataSource dataSource = jdbcTemplate.getDataSource(); Connection con = DataSourceUtils.getConnection(dataSource); IDatabaseConnection dbUnitCon = new DatabaseConnection(con); IDataSet dataSet = new FlatXmlDataSet(new FileInputStream("./src/test/resources/dbunit/"+getDbUnitFileName())); try { DatabaseOperation.REFRESH.execute(dbUnitCon, dataSet); } finally { DataSourceUtils.releaseConnection(con, dataSource); } } /** * You must return the filename of the dbunit test data. * @return the filename of the dbunit test data. */ protected abstract String getDbUnitFileName(); /** * You must return the bean name of the class under test. After the constructor * finishes, you will find this object in the protected field {@code classUnderTest} * * @return the bean name of the class under test */ protected abstract String getBeanName(); Then you subclass the test like this: public MyDaoTest extends AbstractDbUnitTestCase { // class under test private MyDao dao; public MyDaoTest( ) { super(); dao = (MyDao) super.classUnderTest; } public String getDbUnitFileName() { return "MyDaoTest.xml"; } public String getBeanName() { return "myDao"; } public void testSomething() { // assert dao.doesSomething() } } wire your spring bean into applicationContext.xml, and also setup a transaction manager in spring, and you should be set to go. Before every test method, DbUnit will do a REFRESH, and roll it all back after the test method. --davis On Mon, Aug 3, 2009 at 1:39 PM, Karthik Krishnan<krishnan.1000@...> wrote: > Hi Carfield, > > Thanks for your update. I believe that Spring's testing framework has > something like this but I have not investigated it. There does not seem to > be a direct way to hook onto to DbUnit with Spring, but let me look into it. > > Thanks, > > Kartik > > On Sat, Aug 1, 2009 at 8:13 AM, Carfield Yim <carfield@...> > wrote: >> >> I've tried to do something similar, but it turn out having very very >> slow test. Instead, turn off transaction in test case and just delete >> everything before next test case work better for me, btw, it was >> tested in oracle, sybase and sql server, all have similar behavior. >> >> On Fri, Jul 31, 2009 at 8:00 AM, Karthik >> Krishnan<krishnan.1000@...> wrote: >> > Hi, >> > >> > I have worked with DbUnit and I think it is the best tool to for db >> > tests. I >> > have an issue I hope DbUnit addresses this issue. In my project, we use >> > Callable Statements to make CRUD calls. Some of the calls are complex >> > package calls. To test crud operations, what we would like to do is >> > >> > 1. invoke a CRUD call (Create) and committed >> > 2. Test if data exists >> > 3. After the test has been executed, roll back all changes automatically >> > unconditionally (when the test passes, fails or if an exception is >> > thrown). >> > From what I understand is that DatabaseOperation.INSERT should followed >> > by >> > DatabaseOperation.DELETE which are two separate operations but should be >> > transactional. What I would prefer is that the changes were rolled back >> > instead of calling delete. Because a successful insert may involve >> > different >> > tables with different constraints, it is very difficult for us to delete >> > multiple entries from different tables. >> > >> > Is there a facility for this purpose? >> > >> > Thanks, >> > >> > Kartik >> > >> > >> > ------------------------------------------------------------------------------ >> > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 >> > 30-Day >> > trial. Simplify your report design, integration and deployment - and >> > focus >> > on >> > what you do best, core application coding. Discover what's new with >> > Crystal Reports now. http://p.sf.net/sfu/bobj-july >> > _______________________________________________ >> > dbunit-user mailing list >> > dbunit-user@... >> > https://lists.sourceforge.net/lists/listinfo/dbunit-user >> > >> > >> >> >> ------------------------------------------------------------------------------ >> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 >> 30-Day >> trial. Simplify your report design, integration and deployment - and focus >> on >> what you do best, core application coding. Discover what's new with >> Crystal Reports now. http://p.sf.net/sfu/bobj-july >> _______________________________________________ >> dbunit-user mailing list >> dbunit-user@... >> https://lists.sourceforge.net/lists/listinfo/dbunit-user > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus > on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > dbunit-user mailing list > dbunit-user@... > https://lists.sourceforge.net/lists/listinfo/dbunit-user > > -- Zeno Consulting, Inc. home: http://www.zenoconsulting.biz blog: http://zenoconsulting.wikidot.com p: 248.894.4922 f: 313.884.2977 ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ dbunit-user mailing list dbunit-user@... https://lists.sourceforge.net/lists/listinfo/dbunit-user |
| Free embeddable forum powered by Nabble | Forum Help |