1 package junit.extensions; 2 3 import junit.framework.*; 4 5 /** 6 * A Decorator to set up and tear down additional fixture state. 7 * Subclass TestSetup and insert it into your tests when you want 8 * to set up additional state once before the tests are run. 9 */ 10 public class TestSetup extends TestDecorator { 11 12 public TestSetup(Test test) { 13 super(test); 14 } 15 public void run(final TestResult result) { 16 Protectable p= new Protectable() { 17 public void protect() throws Exception { 18 setUp(); 19 basicRun(result); 20 tearDown(); 21 } 22 }; 23 result.runProtected(this, p); 24 } 25 /** 26 * Sets up the fixture. Override to set up additional fixture 27 * state. 28 */ 29 protected void setUp() throws Exception { 30 } 31 /** 32 * Tears down the fixture. Override to tear down the additional 33 * fixture state. 34 */ 35 protected void tearDown() throws Exception { 36 } 37 } 38