EasyMock 和 Ibatis
在我的 DAO 层中,我通过调用存储过程来完成所有数据库工作。 我想知道是否有人成功使用 EasyMock 测试他们的 DAO 层?
谢谢 达米安
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说那是不可能的。没有办法断言(使用 EasyMock 或其他模拟框架)DAO 实际上调用了某个存储过程,验证它做了什么等。
使用 DAO + EasyMock 唯一能做的就是模拟/存根 DAO,但是然后你'我们不是测试 DAO,而是测试作用于 DAO 的协作者(如果我们说的是 MVC,通常是某种控制器)。
要进行 DAO/StoredProcedures 的集成测试,我建议 DBUnit:
如果您的DAO 为某些业务实体提供CRUD,您可以测试 DAO 的每个操作:
testInsert
- 将新实体插入数据库然后重新加载并比较testUpdate
- 修改现有实体,保存到DB 和重新加载/比较testDelete
- 从 (1) 中删除一些实体,然后尝试加载它并断言它失败(也可以检查是否没有其他内容被删除)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)