ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Burke.Kevin" <Kevin.Bu...@cic.gc.ca>
Subject RE: Begin book addresses mock object testing only (alternatives?)
Date Wed, 08 Jul 2009 17:57:26 GMT

If you are using Spring to wire up your iBatis configuration, there is
an abstract Spring class for performing DAO tests that encapsulates
transaction management around each test. You can perform the necessary
iBatis calls, and Spring will rollback all of the test changes. 

If you require more details on this class, see the Spring API Javadocs

Here is an example base class I use for all of my DAO tests. Simply
subclass this for each test class, ensuring that if you override the
onSetUp() or onTearDown() methods (instead of the jUnit setUp() or
tearDown() superclass methods), you also invoke the super.onSetUp() or
super.onTearDown() methods from within.  I use a separate
applicationContext file for these testsm as noted below.

Hope this helps,


------- Code Sample --------

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

 * Abstract base class for DAO tests that require rollback functionality
when testing 
 * CRUD operations.
 * @author Kevin.Burke
public 	abstract class 	AbstractBaseDaoTestCase
	protected Log	log	= LogFactory.getLog( this.getClass() );

	public AbstractBaseDaoTestCase()
    protected String[] getConfigLocations()
        String[] paths = new String[] {
        return paths;
    public Object getBean( String beanName )
    	return getApplicationContext().getBean( beanName );


To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org

View raw message