Posts

Showing posts with the label Junit4

Cleanup After All Junit Tests

Answer : I'm using JUnit 4.9. Will this help?: import junit.framework.TestCase; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({First.class,Second.class,Third.class}) public class RunTestSuite extends TestCase { @BeforeClass public static void doYourOneTimeSetup() { ... } @AfterClass public static void doYourOneTimeTeardown() { ... } } Edit: I am quite positive (unless I misunderstand your question) that my solution is what you are looking for. i.e. one teardown method after all your tests have ran. No listener required, JUnit has this facility. Thanks. I recommend to use org.junit.runner.notification.RunListener, example: public class TestListener extends RunListener { @Override public void testRunStarted(Description description) throws Exception { // Called be...