Results 1 to 3 of 3

Thread: Testing JdbcDaoSupport subclasses with junit

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Vermont
    Posts
    27

    Default Testing JdbcDaoSupport subclasses with junit

    I need some JUnit advice for testing my JdbcDaoSupport sub classes.

    My methods inside my classes call the getConnection() method from JdbcDaoSupport. My first thought was to subclass my class and overload the getConnection() method with one that would return a mock connection. This does not work because the getConnection() method is final. My next thought was to provide a mock datasource to
    JdbcDaoSupport through the setDataSource() method. The mock datasource would then return a mock connection. This also does not work because the setDataSource() method on JdbcDaoSupport calls many methods on the datasource and I can't implement those on my mock. I then though about subclassing again and overloading setDataSource() but it too is final.

    So...How is everyone unit testing their JDBC DAOs in isolation from a DB? Am I missing something obvious?

    Thanks
    David Noel

  2. #2
    Join Date
    Aug 2004
    Location
    Germany, Magdeburg
    Posts
    279

    Default

    Mostly DAO testing is not done using mocks. Using a data base is 'always best' because it also acts like a (very) basic integration test. Best would be using the production DBMS (database management system). In a Hibernate project I prefer the HSQLDB database.


    Cheers,

    Martin (Kersten)

  3. #3
    Join Date
    Oct 2004
    Location
    Rotterdam, Netherlands
    Posts
    90

    Default

    David,

    you might like to check out the org.springframework.test package. It contains superclasses that create and rollback a transaction and can help get the DB in a known state and run tests.

    Also search for AbstractTransactionalSpringContextTests and AbstractTransactionalDataSourceSpringContextTests in the forums.

    Rgrds, Thomas

Similar Threads

  1. Junit testing with Ant & HSQLDB in memory
    By teneighty in forum Architecture
    Replies: 6
    Last Post: Jan 1st, 2009, 04:10 PM
  2. JDO Transactions and JUnit testing
    By markds75 in forum Data
    Replies: 2
    Last Post: Sep 17th, 2005, 01:46 AM
  3. Please help! Unit testing code for JPetStore
    By lakershen in forum Container
    Replies: 4
    Last Post: Jan 13th, 2005, 05:00 PM
  4. Spring and (J)unit testing: where?
    By Edward Kenworthy in forum Meta
    Replies: 1
    Last Post: Sep 21st, 2004, 12:38 PM
  5. Has anybody gotten Junit testing to work under wsad 5.1.2?
    By theone in forum SpringSource Tool Suite
    Replies: 0
    Last Post: Aug 24th, 2004, 12:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •