Your usage of the Suite to do the teardown is causing you problems, for a number of reasons, but specifically the fact that you can't predict the order in which Eclipse (or Maven) will execute your tests. For a fuller explanation, see my answer to Has JUnit4 begun supporting ordering of test? Is it intentional?, but because Eclipse & maven are finding the classes by reflection (annotations), you can't guarantee in which order the classes will be found. [* you can with maven and runOrder, see point 3 below]
Eclipse (and Maven) treats a Suite just like a Test, it's found and run via the same mechanism, and the order in which they are executed in highly dependent on the JVM.
So, if you have Suite A (which contains Test B and C) and Test D, then you'll execute the following (in an unpredictable order):
A (which will execute B & C)
B
C
D
In general, you should try and maintain a symmetry, doing the setUp/teardown in the same place.
So, you have the following options:
- Only use @BeforeClass/@AfterClass (or better @ClassRule, ExternalResource), and remove your test suite. This is your cleanest option, because you're doing the setup for each test class.
- Only run the test Suite from Eclipse, and use the Maven Surefire Includes/Excludes to do the same in Maven. Note that if you only ever run the test suite, the setup is better done in the Suite rather than in each class. This gives problems when running just a single test from Eclipse however.
- Run the tests in a particular order. This can't be done in Eclipse but can in Maven, see surefire:test runOrder. You'll have to have some naming convention.
- Use TestNG, which explicitly supports ordering of classes, and is probably easier to setup with the list of classes to run, but you'll still have the same sort of problems with your setup/teardown.