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
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:
In case your DAO provides CRUD for some business entity you can test each operation of your DAO:
testLoad
- load from DB and compare with (1)testInsert
- insert new entity to DB then reload and comparetestUpdate
- modify existing entity, save to DB and reload/comparetestDelete
- delete some entity from (1), then try to load it and assert it fails (also good to check that nothing else was deleted)