SetUp and tearDown once for one junit class
1 posts in topic
Flat View  Flat View

Posted By:   Bharath_J
Posted On:   Wednesday, November 23, 2005 08:03 AM


I want to write junit test cases in which setUp and teardown are called only once. I have used the technique of wrapping all my test suites in a subclass of TestSetup. It works.

I am developing a framework specific to my organization in which all developers will write test cases in JUNIT and all of them would want to run setUp and tearDown once. Now i want to write a junit class, and when the developers extend my class their test files should run only one setUp and tearDown.

can anyone help me with this? Thanks in advance.

Re: SetUp and tearDown once for one junit class

Posted By:   Arun_Kumar  
Posted On:   Wednesday, December 7, 2005 08:20 AM


U can write a BaseTestCase class extends TestCase having only the setUp() and tearDown() classes.This setUp() method can hold all data and object initializations required to be used by other test casse classes.

Thus when u write a SampleTest it just extends the BaseTestCase and u can have your test methods in that.U just need to call super.setUp() and super.tearDown() in your SampleTest class's setUp() and tearDown() methods respectively.

This reduces the redundant codes present in the setUp() methods of various TestCase classes.
About | Sitemap | Contact