开发者

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:

  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:

  • testLoad - load from DB and compare with (1)
  • testInsert - insert new entity to DB then reload and compare
  • testUpdate - modify existing entity, save to DB and reload/compare
  • testDelete - delete some entity from (1), then try to load it and assert it fails (also good to check that nothing else was deleted)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜