I would say this is a good place of Inversion of Control... Your active
data objects have to get a persistence framework reference from
somewhere, right? Personally, I would not code them directly against
Hibernate. Have them depend on a service which implements an interface,
and have your container provide that for them. In production, this
service is a Hibernate implementation. In tests it's a mock.

The key is to have this separation. You can then test your persistence
separate from the data objects, which are separate from the actions. 

Yes, at some point you need to test the DAO/Store code (the Hibernate
implementation of the interface). For that you can do interesting things
with Hibernate's SchemaBuilder tool (and ant task) and an in-memory
database like HSQL. 

I'll let Mike and others elaborate on any more details they think are
needed... 

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, June 24, 2003 2:16 PM
> To: [EMAIL PROTECTED]; 
> [EMAIL PROTECTED]
> Subject: RE: [OS-webwork] WebWork Getting Started Guide 
> -Mock/Unit Testing with Hibernate
> 
> 
> ***************** 
> I am double posting this on webwork's and hibernate's mailing 
> list. Maybe one of the hibernate guys can answer how to mock 
> hibernate transparently.
> *****************
> 
> Incidentally, since my actions are fairly atomic and 
> functionally aligned, extracting the hibernate logic to a 
> service (dao, etc) would have left the actions with one line 
> of code.  It seemed kind of needless.  Though, I do get your point.  
> 
> I also went with the active data object approach to hibernate (meaning
> dataObject.persist() instead of service.persist(dataObject) 
> -- which I like).  However, it means that I don't really have 
> a great place to put service methods other than introducing 
> another layer.  
> 
> From a testing perspective, moving the logic to a service 
> isolates the action from the service and allow unit testing 
> on the action.  However, doesn't that move the problem to the 
> service?  In other words, I have the same issue trying to 
> unit test that service.  Either way, I still have to find a 
> good way to mock hibernate.  I do have hibernate itself 
> hidden behind a service.  So, maybe I can somehow mock that.  
> It would be nice if I could figure a way to do it generically 
> so that I wouldn't have so much additional code the write.  
> Maybe this is a good place for an interceptor of some type.
> 
> LES 


-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Reply via email to