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 开发者_Go百科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:
- Put testdata into database (if you're using jUnit do this in @Before method)
- Call DAO method under test
- If method returned any result, compare this to expected data in (1)
- 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:
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)
精彩评论