ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Jenkins <krisajenk...@yahoo.co.uk>
Subject Re: Can't test DAO
Date Thu, 06 Jan 2005 14:04:50 GMT
Hugo Palma wrote:

> I'm using Spring with iBATIS SqlMap.
> I'm trying to test my DAOs with junit and easyMock.
> All my DAOs extend 
> org.springframework.orm.ibatis.support.SqlMapClientDaoSupport, as 
> such, for doing a database operation i invoke method 
> getSqlMapClientTemplate().<whatever>.
> What seemed like an obvious way to test the DAO was to create a mock 
> of the sqlMapClientTemplate object(using easyMock) so that i could 
> configure it's behaviour. But then the problems started. First i 
> couldn't get the DAO instance from the spring application context 
> without defining the "dataSource" and "configLocation" properties 
> which i shouldn't have to define for the test because i'll be using a 
> mock template anyway. I defined the properties anyway but then i came 
> to a full stop as i realized that class 
> org.springframework.orm.ibatis.SqlMapClientTemplate is in fact not an 
> interface, this makes it impossible for easyMock to generate a mock 
> object for it.
> So my question is, is there any easy way i can this tests ?
> If you think this is more a spring list question please tell me.

Personally I wouldn't mock SqlMapClient, any more than I'd mock 
java.util.ArrayList.  I only unit test my code, not 3rd party code.  
After all, it should already be thoroughly tested in development and the 
real world.

If you're prepared to accept that thinking, then testing each DAO in 
isolation from *your* other classes is easy - just pass a different 
sql-map-config.xml to Spring's SqlMapClientBuilder.


Kris Jenkins
Email:  kris@jenkster.com
Blog:   http://cafe.jenkster.com/
Wiki:   http://wiki.jenkster.com/

No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.8 - Release Date: 03/01/2005

View raw message