-->
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.  [ 5 posts ] 
Author Message
 Post subject: Unit Testing in Isolation Concern
PostPosted: Mon Feb 04, 2008 6:26 pm 
Beginner
Beginner

Joined: Thu Dec 13, 2007 2:32 pm
Posts: 26
Hi Guys,

I am unit testing some class with TestNG framework, we are using Hibernate as our base APIs with an abstraction built on top of it. I came across an issue, that I'd like to know answers to.

I have a test class which has test cases numbered from 1 to 3 ( assume ).

typically, i do :

@BeforeClass deleteAllDataInDataBase( )

// run test cases

@AfterClass deleteAllDataInDataBase( )


Test cases work fine and everything is good and dandy. Yesterday i was trying to simulate a failure in multi threading environment ( i was skeptical of a block of code that was written in one of the Base classes ). And basically i created something like

run( ){

TestNG testNG = new TestNG( );
testNG.run( );
}

now i create an Executors.newFixedThreadPool( 10 );
and then do an execute twice or thrice on the above run( ) method in a typical runnable in a typical failure type while(true) loop.

In doing so, Hibernate gives me a unique violation exception ( as i would expect ).

So from above scenario, my question is, if i am running my test suite on DB. and if someone else is running the same test suite on his machine, then it should be giving the unique exception as expected.

Is there a work around / am i missing something ?

Regards
Vyas, Anirudh

_________________
Regards,
Vyas, Anirudh


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 05, 2008 3:42 pm 
Beginner
Beginner

Joined: Thu Dec 13, 2007 2:32 pm
Posts: 26
Wow, any thoughts guys ?


Regards
Vyas, Anirudh

_________________
Regards,
Vyas, Anirudh


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 05, 2008 5:18 pm 
Newbie

Joined: Tue Feb 05, 2008 11:16 am
Posts: 5
Why do you expect Unique Violation exceptions? Does your test data have application-defined IDs that it reuses every time you test?

Would you and another developer run the tests against the same database?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 9:45 am 
Beginner
Beginner

Joined: Thu Dec 13, 2007 2:32 pm
Posts: 26
Actually,

I am assigning ids at the moment. like <generator class="assigned" />.

and yes, others are also running the same tests, basically all our tests are in maven repository, and locally anyone doing mvn clean install ( just a build that is ), it would run tests automatically, and thereby giving them the results etc.

Regards
Vyas, Anirudh

_________________
Regards,
Vyas, Anirudh


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 07, 2008 5:40 pm 
Newbie

Joined: Tue Feb 05, 2008 11:16 am
Posts: 5
Well, if you are assinging the IDs yourself you could assign them with a random number generator or something based on the timestamp of when the test was run. This would ensure that the IDs were different, and get around the NonUnique problem.

You could get intense and add in some unique machine identifier to the IDs so that different machines running the tests would not use the same IDs.
Hope this helps.
Frank


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