KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > extensions > TestSetup


1 package junit.extensions;
2
3 import junit.framework.Protectable;
4 import junit.framework.Test;
5 import junit.framework.TestResult;
6
7 /**
8  * A Decorator to set up and tear down additional fixture state. Subclass
9  * TestSetup and insert it into your tests when you want to set up additional
10  * state once before the tests are run.
11  */

12 public class TestSetup extends TestDecorator {
13
14     public TestSetup(Test test) {
15         super(test);
16     }
17
18     @Override JavaDoc
19     public void run(final TestResult result) {
20         Protectable p= new Protectable() {
21             public void protect() throws Exception JavaDoc {
22                 setUp();
23                 basicRun(result);
24                 tearDown();
25             }
26         };
27         result.runProtected(this, p);
28     }
29
30     /**
31      * Sets up the fixture. Override to set up additional fixture state.
32      */

33     protected void setUp() throws Exception JavaDoc {
34     }
35
36     /**
37      * Tears down the fixture. Override to tear down the additional fixture
38      * state.
39      */

40     protected void tearDown() throws Exception JavaDoc {
41     }
42 }
Popular Tags