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