Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JUnit fixture

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys,
I had been searching for a code snippet on how to do this in JUnit framework.
In a normal testcase, the test is run in the following manner.
setUp -> testMethod1 -> tearDown
setUp -> testMethod2 -> tearDown
Now, I need to startup a fixture once for all the testmethods
and I had overriden the setUp/tearDown method in the TestSetup.
Now my testcase is ran as
setUp -> testMethod1 -> testMethod2 -> tearDown
However, I want to have this kind of behavior in my code.
startFixture (executed only once)
setUp -> testMethod1 -> tearDown
setUp -> testMethod2 -> tearDown
stopFixture
Having a flag in the setup will be an easy one but I want know a kinda "official" way on how JUnit framework could be used. Or do I have to implement my TestListener for this?
There might have been the same question as this in the forum; if there is, could you please give me the link to it...
Thanks,
mavedrive;
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Maverick Lasa:
...
However, I want to have this kind of behavior in my code.
startFixture (executed only once)
setUp -> testMethod1 -> tearDown
setUp -> testMethod2 -> tearDown
stopFixture
...


That looks exactly like what junit.extensions.TestSetup provides, so what's the problem?

TestSetup's setUp() method is called once before the entire suite; tearDown() is called once afterwards. The setUp() and tearDown() methods within YourTestClass are still executed before and after each individual unit test method within YourTestClass.
 
Maverick Lasa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Billy,
Thanks. I had just tried experimenting with it.
I thought that when a TestSetup is introduced
the setUp/tearDown methods won't be called anymore
before/after each test methods.
Thanks a lot anyway,
mave
 
Yup, yup, yup. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic