• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TestSetup(Test test)14     public TestSetup(Test test) {
15         super(test);
16     }
17 
18     @Override
run(final TestResult result)19     public void run(final TestResult result) {
20         Protectable p = new Protectable() {
21             public void protect() throws Exception {
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      */
setUp()33     protected void setUp() throws Exception {
34     }
35 
36     /**
37      * Tears down the fixture. Override to tear down the additional fixture
38      * state.
39      */
tearDown()40     protected void tearDown() throws Exception {
41     }
42 }