javadaoibatiseasymockdata-access-object

EasyMock and Ibatis


In my DAO layer I am doing all my database work by calling stored procedures. I was wondering has anyone been successful in testing their DAO layer using EasyMock?

Thanks Damien


Solution

  • I would say that's impossible. There's no way to assert (with EasyMock or other mocking framework) that the DAO actually called some stored procedure, verify what it did etc.

    The only thing you can do with DAO + EasyMock is to mock/stub the DAO, but then you're not testing the DAO but instead the collaborator acting on the DAO (typically some kind of controller if we're speaking MVC).

    To do integration test of DAO/StoredProcedures I recommend DBUnit:

    1. Put testdata into database (if you're using jUnit do this in @Before method)
    2. Call DAO method under test
    3. If method returned any result, compare this to expected data in (1)
    4. If method performed some inserts/updates, call a "read method" and compare result with (1)

    In case your DAO provides CRUD for some business entity you can test each operation of your DAO: