Before every JUnit test I run certain things need to be set up. Some properties need to be loaded, a database connection needs to be made, a separate J2SE application needs to be started, etc. When every single test has finished the database connection can be killed and J2SE application shut down.
I can accomplish this by using @BeforeClass and @AfterClass annotations in a test suite, but that limits me to only being able to run tests inside the suite. If I want to run an individual test outside of a suite it won't run the suite setup and teardown methods. Likewise, if I want to run an individual test method (through an IDE) it won't run the setup and teardown from the suite.
Is there a way to setup JUnit tests so that, no matter how they're run, through a suite, or a test case, or an individual method, they always run a setup method only once before running anything, and a teardown only once after every test has been executed? Having all of the test cases extend an abstract class with a static initializer solves the setup problem, but not teardown.