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;
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.
Joined: Oct 18, 2003
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