001package junit.extensions; 002 003import junit.framework.Protectable; 004import junit.framework.Test; 005import junit.framework.TestResult; 006 007/** 008 * A Decorator to set up and tear down additional fixture state. Subclass 009 * TestSetup and insert it into your tests when you want to set up additional 010 * state once before the tests are run. 011 */ 012public class TestSetup extends TestDecorator { 013 014 public TestSetup(Test test) { 015 super(test); 016 } 017 018 @Override 019 public void run(final TestResult result) { 020 Protectable p = new Protectable() { 021 public void protect() throws Exception { 022 setUp(); 023 basicRun(result); 024 tearDown(); 025 } 026 }; 027 result.runProtected(this, p); 028 } 029 030 /** 031 * Sets up the fixture. Override to set up additional fixture state. 032 */ 033 protected void setUp() throws Exception { 034 } 035 036 /** 037 * Tears down the fixture. Override to tear down the additional fixture 038 * state. 039 */ 040 protected void tearDown() throws Exception { 041 } 042}