-->
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.  [ 8 posts ] 
Author Message
 Post subject: Units Tests and Bag Class (and equals() method)
PostPosted: Thu Apr 29, 2004 11:44 pm 
Newbie

Joined: Thu Apr 29, 2004 11:41 pm
Posts: 4
Location: Columbus, OH
If equals() is not implemented on Bag, how should I do a unit test like the following:

Code:
PersistedObject p = new PersistedObject();
p.setSomeProperty("someValue");

session.save(p);

PersistedObject p2 = session.load(p.getId());

assertEquals(p, p2);



It will always fail, even when it should pass.

_________________
. . .

Jess


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 11:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Your equals() method should certainly not include collection-valued properties. They are not part of the natural key.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 12:03 am 
Newbie

Joined: Thu Apr 29, 2004 11:41 pm
Posts: 4
Location: Columbus, OH
How then do you recommend that I ensure that collections were persisted as I need them to be?

_________________
. . .

Jess


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 1:29 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Eheh, that was the first thing I disagreed with Gavin. Not implementing bag equals properly is inconsistent but efficient.
You may be able to find a patch for that in Jira.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 1:32 pm 
Newbie

Joined: Thu Apr 29, 2004 11:41 pm
Posts: 4
Location: Columbus, OH
Thanks, I don't agree or not with implementing equals() on the Bag class. I saw the older thread on this where you two talked about it.

I just need to know what the recommended way is to unit test loading classes that have collections on them? Is using equals() the wrong way? If so, then how should I go about it?

Thanks for your input.

_________________
. . .

Jess


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 1:52 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Well your unit tests should not test Hibernate (it has its own unit test suite).
But I usually test either a particular proeprty or the natural key. I do not do object equals

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Interesting comment.
PostPosted: Fri May 21, 2004 9:23 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
Our continuous build server currently spends most of its time executing our Hibernate DAO unit tests. I think most of this time is due to dbunit tearing down and rebuilding the integration db.

Our department has been pretty dogmattic in writing unit tests for our domain and dao layers. It's an interesting comment because I know developers on my team would love to stop writing unit tests for this layer if given the choice.

If I'm playing devil's advocate I'd say that these unit tests have value because we are asserting that returned entities are in fact the ones that a client layer are expecting.

I hope I've been clear. Could you elaborate on your comment Emmanuel?


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 6:32 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Actually I do unit test my DAO because my Hibernate usage logic may be broken.
But I do not test the Hibernate capability of loading a collection.

To increase my early devs, I start with HSQLDB and SchemaExport. That's really cool, no need of DB instance, memory DB, no network usage etc... But sooner or later you have to switch to your real DB

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.