问题
I use JUnit 3.x TestRunner that intantiates all tests at once before running them.
Is there a Test Runner available that would create each test (or at least each test suite's tests) just before running them?
I can use JUnit 4.x runners but my tests are 3.x tests.
回答1:
In JUnit 3 you'd need to write your own TestSuite class that delayed instantiation of the tests in the suite.
回答2:
You are probably doing it wrong.
Each unit test should be self-contained and not depend on any other test results. Otherwise when one of the tests break it will break all the tests that depend on it. So you will see a lot of errors without easy way to understand what is the actual cause. On the other hand if all unit tests are independent a broken test is extremely easy to debug and fix.
EDIT: I am assuming the reason you ask the original question is because you have some dependencies in your test. If I am wrong please ignore this answer :)
来源:https://stackoverflow.com/questions/1191995/junit-test-runner-that-creates-tests-just-before-running-them