我使用春季和休眠我的数据访问层 我想有一些关于如何构建我的单元测试,以测试hibernate是否有效地插入到子表(父Hibernate映射在集合上都有级联)。 什么,我知道我不应该混道的单位testing.So假设在我测试的家长DAO方法saveWithChild:测试休眠父母/子女关系
public void testSaveWithChild() {
Child c1 = new Child("prop1", "prop2", prop3);
Child c2 = new Child("prop4", "prop4", prop3);
Parent p = new Parent("prop6","prop7");
p.addChild(c1);
p.addChild(c2);
Session session = MysessionImplementation.getSession();
Transaction tx = session.begingTransaction();
ParentDAO.saveWithChild(p);
tx.commit();
Session session1 = MysessionImplementation.getSession();
//now it is right to call child table in here?
Child c1fromdb = (Child)session1.get(ChildClass.class,c1.getID());
Child c2fromdb = (Child)session1.get(ChildClass.class,c2.getID());
//parent asserts goes here
//children asserts goes here.
}
我不知道,但我不觉得舒适做this.Isn有没有更好的办法? 你将如何检查这些东西?谢谢阅读。 ;)
谢谢你会尝试 – 2009-08-05 17:16:51