如何对扩展SqlMapClientDaoSupport的DAO进行单元测试 [英] How to unit test a DAO that is extending SqlMapClientDaoSupport

查看:531
本文介绍了如何对扩展SqlMapClientDaoSupport的DAO进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring DA有助于编写DAO。当使用iBATIS作为持久性框架并扩展SqlMapClientDaoSupport时,应该为DAO设置SqlMapClient模拟,但我不能这样做。 SqlMapClientTemplate不是一个接口,EasyMock不能为它创建一个模拟。

Spring DA helps in writing DAOs. When using iBATIS as the persistence framework, and extending SqlMapClientDaoSupport, a SqlMapClient mock should be set for the DAO, but I can't do it. SqlMapClientTemplate is not an interface and EasyMock cannot creates a mock for it.

推荐答案

DAO和单元测试相处不好!
在没有任何业务逻辑且专注于数据库访问的组件中模拟任何东西是没有意义的。
您应该尝试编写集成测试。请查看Spring参考文档,第8.3章: http: //static.springframework.org/spring/docs/2.5.x/reference/testing.html

DAO and unit tests do not get along well ! That does not make sense to mock anything in a component that does not hold any business logic and is focused on database access. You should try instead to write an integration test. Take a look at the spring reference documentation, chapter 8.3 : http://static.springframework.org/spring/docs/2.5.x/reference/testing.html

这篇关于如何对扩展SqlMapClientDaoSupport的DAO进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆