[英]Tools and Methods for testing Service/DAO layers in Java
I am trying to figure out the best way(s) to test Service and DAO layers. 我试图找出测试服务和DAO层的最佳方法。 So, a few sub questions... 那么,一些子问题......
I am looking for any good documentation, articles, or references in this area along with any tools to help automate the process. 我在这个领域寻找任何好的文档,文章或参考文献以及任何有助于自动化过程的工具。 I already know about JUint for unit testing and Hudson for CI. 我已经了解了JUint的单元测试和Hudson的CI。
Get Growing Object-Oriented Software, Guided by Tests . 在测试的指导下,获得不断增长的面向对象软件 。 It has some great tips about how to test database access. 它有一些关于如何测试数据库访问的好技巧。
Personally, I usually break the DAO tests in 2, a unit test with a mocked database to test functionality on the DAO, and an integration test, to test the queries against the DB. 就个人而言,我通常打破2中的DAO测试,使用模拟数据库进行单元测试以测试DAO上的功能,并进行集成测试,以测试针对数据库的查询。 If your DAO only has database access code, you won't need a unit test. 如果您的DAO只有数据库访问代码,则不需要进行单元测试。
One of the suggestions from the book that I took, is that the (integration) test has to commit the changes to the DB. 我所采用的书中的一个建议是(集成)测试必须将更改提交给DB。 I've learn to do this, after using hibernate and figuring out that the test was marked for rollback and the DB never got the insert statement. 我已经学会了这样做,在使用hibernate并确定测试标记为回滚并且DB从未得到插入语句之后。 If you use triggers or any kind of validation (even FKs) I think this is a must. 如果您使用触发器或任何类型的验证(甚至是FK),我认为这是必须的。
Another thing, stay away from dbunit, it's a great framwork to start working, but it becomes hellish when a project becomes something more than tiny. 另一件事,远离dbunit,开始工作是一个很好的框架,但当项目变得非常小时,它变得很糟糕。 My preference here, is to have a set of Test Data Builder classes to create the data, and insert it in the setup of the test or in the test itself. 我的偏好是拥有一组Test Data Builder类来创建数据,并将其插入测试设置或测试本身。
And check dbmigrate, it's not for testing, but it will help you to manage scripts to upgrade and downgrade your DB schema. 并检查dbmigrate,它不是用于测试,但它将帮助您管理脚本以升级和降级数据库架构。
In the scenario where the DB server is shared, I've creates one schema/user per environment. 在共享数据库服务器的场景中,我为每个环境创建了一个模式/用户。 Since each developer has his own "local" environment, he also owns one schema. 由于每个开发人员都有自己的“本地”环境,因此他还拥有一个模式。
Here are my answers : 以下是我的答案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.