A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Engineering
»
Testing
Author
Creating shared object...but only once..in test case
A Kumar
Ranch Hand
Joined: Jul 04, 2004
Posts: 973
posted
Jan 10, 2008 20:06:00
0
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
posted
Jan 11, 2008 02:37:00
0
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: 973
posted
Jan 11, 2008 02:54:00
0
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
posted
Jan 11, 2008 06:01:00
0
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: 973
posted
Jan 11, 2008 11:00:00
0
Thanks Lasse !!!
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Creating shared object...but only once..in test case
Similar Threads
JUnit : with respect to setup and teardown methods
Static block and method.
setUp and teardown not working
code problem!!!!
java STATIC fields.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter