aspose file tools*
The moose likes Testing and the fly likes Creating shared object...but only once..in test case Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Creating shared object...but only once..in test case" Watch "Creating shared object...but only once..in test case" New topic
Author

Creating shared object...but only once..in test case

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
In Junit ......test case...

the setup gets executed everytime.....so i put a connection object code...

Then for all 3 testXXX methods...in the class....it gets executed..

Is there a way where we can restrict the same for only one time....and still the object is accesible ....for all 3 methods...

I tried static block..
if constructor exists then setup method is not called....

but no success???
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
First of all, which version of JUnit are you using? 3.8 or 4.x?

Also, I don't quite understand what you mean by the setup method not getting called if a constructor is present?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Am using Junit 3.8.1


Sorry abt the constructor part...

I had put system.out statements in both ....Contstructot and setUp..

When i ran it printed ..Constrcutor...3 times..and not Setup..

I had commented out...setup statement...
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by A Kumar:
Am using Junit 3.8.1

Ok. In JUnit 3.8 the recommended way to perform one-time setup and teardown is through the TestSetup class like this.
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Thanks Lasse !!!
 
Don't get me started about those stupid light bulbs.
 
subject: Creating shared object...but only once..in test case