带有 spring JDBC 模板的 DAO:单元测试的最佳方法
使用 Spring JDBC 模板构建的单元/集成测试 DAO 层类的最佳方法是什么?
我想到了三种方法:
1)Mock 库(EasyMock、JMock、Mockito 等) - Spring 框架测试代码使用这种方法 - 他们使用 EasyMock。
2) 嵌入式数据库(H2、HSQL、Derby)
3) 真实数据库 - 与生产中使用的产品相同,在我的例子中为 Sybase ASE - 显然有不同的模式。
Cons:
1)This may slow down unit test execution.
2)Schema is shared between different developers / CI server. So, need to make sure there is no concurrency issue.
有些人认为第一种和第二种方法并不是真正的测试。第二种方法的另一个问题是,我使用的数据库 Sybase ASE 似乎与其中任何一个都不兼容。
想了解最佳实践。
谢谢。
What is the best way to unit/integration test DAO layer classes built using Spring JDBC templates?
Three approaches come to mind:
1) Mock library (EasyMock, JMock, Mockito, etc) - Spring framework test code makes use of this approach - They use EasyMock.
2) Embedded Database (H2, HSQL, Derby)
3) Real Database - Same product as used in production, Sybase ASE in my case - different schema obviously.
Cons:
1)This may slow down unit test execution.
2)Schema is shared between different developers / CI server. So, need to make sure there is no concurrency issue.
Some people argue that First and Second approaches are not real testing. Additional problem with Second approach is that, the database I use, Sybase ASE doesn't seem compatible with any of them.
Would like to know best practices.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)