-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Non-destructive unit testing
PostPosted: Tue Nov 22, 2005 1:40 am 
Beginner
Beginner

Joined: Tue Oct 25, 2005 2:44 am
Posts: 20
Location: Sydney, Australia
Hi,

I want to unit test the persistence of a single object to the database, then rollback so the test works the next time as well. I'm having problems with the SaveOrUpdate method.

My scenario is:
- Begin transaction
- Retrieve object
- Change object property
- Save changes
- Clear cached objects
- Re-retrieve object
- Check object property changed
- Rollback transaction

This fails as the Save change step (calling ISession.SaveOrUpdate) didn't actually persist, and the ClearCache cancels the changes.

I don't want to use the ISession.Flush method as this doesn't really test the code I use - the ISession.SaveOrUpdate method. Similarly I don't want to commit the transaction as this would interfere with other tests.

Any ideas on how I can get around this?

Cheers


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 26, 2005 9:33 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
I don't have any suggestion, but IMO, you should avoid inter-dependency between unit tests as much as possible (though it can be hard if the initialization is "heavy").

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 27, 2005 8:35 pm 
Beginner
Beginner

Joined: Tue Oct 25, 2005 2:44 am
Posts: 20
Location: Sydney, Australia
This is a test of a single object (Order) which I retrieve, update a field (totalvalue) then save again to check the persistence of that field worked. If it depends on any other object I generally use EasyMock or nMock to reduce interdependancy on any external concerns.

Having said that, I've now read the hibernate 2.0.1 documentation which has explained that persistence is only done by the flush, commit or certain finds so I think what I'm seeking to do is impossible, and I'll just have to live with doing a flush.

Ah well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.