简体   繁体   English

测试hibernate Model / DAO类

[英]Testing hibernate Model/DAO classes

I am currently working on a project with a rather complex data model, a lot of relationships, optional, mandatory etc. We want to test our models and daos, but we are weary of writing all the tests manually. 我目前正在开发一个具有相当复杂的数据模型,许多关系,可选,强制等的项目。我们想测试我们的模型和daos,但我们厌倦了手动编写所有测试。 The biggest problem actually is filling the model objects to be tested with sample data. 实际上,最大的问题是用样本数据填充要测试的模型对象。 For a simple model this is easy, sure, but the problem comes in when you have a lot of mandatory relationships and thus need to setup a big object graph for each test. 对于一个简单的模型,这很容易,当然,但是当你有很多强制关系时需要为每个测试设置一个大的对象图。

Does any one know any tools or frameworks that simplify testing hibernate models/dao's? 有没有人知道任何简化测试hibernate models / dao的工具或框架?

Thanks! 谢谢!

Take a look at http://code.google.com/p/template4/ . 请查看http://code.google.com/p/template4/ It allows generating hibernate data using patterns. 它允许使用模式生成hibernate数据。

I have always created the data in the DB first using SQL scripts rather than creating the data programmatically using Hibernate. 我总是首先使用SQL脚本在数据库中创建数据,而不是使用Hibernate以编程方式创建数据。 The SQL file contains just a bunch of insert statement that get executed against an embedded DB. SQL文件只包含一堆针对嵌入式DB执行的insert语句。 Using the H2 db, my driver URL is the following: 使用H2 db,我的驱动程序URL如下:

jdbc:h2:mem:;MODE=Oracle;INIT=RUNSCRIPT FROM 'test/conf/createDb.sql' jdbc:h2:mem :; MODE = Oracle; INIT = RUNSCRIPT FROM'test / conf / createDb.sql'

This automagically creates a new DB and populates the db with test data against which I write me dao test cases. 这会自动创建一个新数据库,并使用测试数据填充数据库,我将其编写为dao测试用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM