Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lasse !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic